Article ID: 132026
Article Last Modified on 1/19/2007
Query: ListTemp
----------------------
Type: Make Table Query
Field: Country
Table: Customers
Total: Group By
You can start by creating a regular select query, adding the Customers
table, and including only the Country field. Then, on the View menu,
click Totals. Leave the Totals row as Group By. Then, on the Query menu,
click Make Table.
Query: AppendListTemp
---------------------
Type: Append Query
Field: Country
Table: Customers
Total: Group By
Sort: Ascending
Append To: Country
Specify ListTemp as the Table Name in the Append dialog box.
Query: DeleteListTemp
---------------------
Type: Delete Query
Field: Country
Table: ListTemp
Delete: Where
Form: Test
-----------------------------
Caption: TestForm
List box:
Name: ShrinkingList
RowSourceType: Table/Query
RowSource: ListTemp
ColumnCount: 1
Private Sub Form_Open(Cancel As Integer)
Dim db As DATABASE
Dim qy As QueryDef
Set db = CurrentDb()
Set qy = db.QueryDefs("DeleteListTemp")
qy.Execute
Set qy = db.QueryDefs("AppendListTemp")
qy.Execute
qy.Close
End Sub
NOTE: In Microsoft Access version 2.0, omit the "Private" keyword. In
that version Private is not valid for Sub procedures.
Private Sub Form_Load()
Me!ShrinkingList.Requery
End Sub
Private Sub ShrinkingList_AfterUpdate ()
On Local Error GoTo ShrinkingList_AfterUpdate_Err
'NOTE: In Microsoft Access version 2.0, omit the Private keyword for the
'Sub statement and the Local keyword for the On Error sentence. In
'version 2.0, those keywords are not valid for these statements.
Dim db As Database, rs As Recordset, criteria As String
Dim UserMessage As String
Set db = CurrentDB()
' Create recordset based on the list box RowSource.
Set rs = db.OpenRecordset(Me!ShrinkingList.RowSource, _
DB_OPEN_DYNASET)
' Check for the existence of Null values.
If IsNull(Me!ShrinkingList) Then
MsgBox "Shrinking List is Null!"
Exit Sub
End If
UserMessage = Me!ShrinkingList
criteria = "[Country] = '" & Me!ShrinkingList & "'"
' Locate the record that was selected in the list box
' list and delete it.
rs.FindFirst criteria
rs.Delete
' Refresh the List Box's RowSource property entries.
Me!ShrinkingList.Requery
' Set the contents of the List Box to blank.
Me!ShrinkingList = Null
' Prompt user.
MsgBox "The Item " & UserMessage & " has been deleted!"
Exit Sub
ShrinkingList_AfterUpdate_Err:
MsgBox Error$
Exit Sub
End Sub
NOTE: The FindFirst criteria can be based on any column of the
list box. If the list box column is not the column set in the
BoundColumn property, change the criteria's list box reference to
ShrinkingList.Column(n), where (n) is the column's zero-based ordinal
position in the RowSource property field list.
Keywords: kbhowto kbprogramming KB132026