Article ID: 132137
Article Last Modified on 11/6/2000
Table: Table1
---------------------------------------------------
Field Name: List
Data Type: Text
Field Size: 15
Caption: Items that will be provided in list
Field Name: Selected
Data Type: Text
Field Size: 5
Caption: Indicates if the item has been selected
Table Properties: Table1
------------------------
PrimaryKey: List
Query: Select Yes
-------------------------------
Field: List
Show: Yes
Criteria: [selected] = "YES"
Query: Select No
------------------------------
Field: List
Show: Yes
Criteria: [selected] = "NO"
Option Explicit
'=======================================================
' The following function opens the table and changes the
' selected value from YES to NO, and then runs the
' query for the two list boxes so that they will display
' the updated values.
'=======================================================
Function Add ()
Dim MyDB As Database
Dim MyTable As Recordset
Dim y As Control
Set y = Me![Field0]
If IsNull(y) Then
MsgBox "Please select something in the list."
Else
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MyTable = MyDB.OpenRecordset("Table1")
MyTable.Index = "PrimaryKey"
MyTable.Seek "=", y
MyTable.Edit
MyTable.[Selected] = "no"
MyTable.Update
MyTable.Close
Me![Field0].Requery
Me![Field2].Requery
End If
End Function
'=======================================================
' The following function opens the table and changes the
' selected value from NO to YES, and then runs the
' query for the two list boxes so that they will display
' the updated values.
'=======================================================
Function Del ()
Dim MyDB As Database
Dim MyTable As Recordset
Dim y As Control
Set y = Me![Field2]
If IsNull(y) Then
MsgBox "Please select something in the list."
Else
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MyTable = MyDB.OpenRecordset("Table1")
MyTable.Index = "PrimaryKey"
MyTable.Seek "=", y
MyTable.Edit
MyTable.[Selected] = "yes"
MyTable.Update
MyTable.Close
Me![Field0].Requery
Me![Field2].Requery
End If
End Function
'=======================================================
' The following function sets all values in the Selected
' field to YES, and then runs the query for the two list
' boxes so that they will display the updated values.
'=======================================================
Function Clear ()
Dim MyDB As Database
Dim MyTable As Recordset
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MyTable = MyDB.OpenRecordset("Table1")
On Error GoTo erhandle
MyTable.MoveFirst
Do Until MyTable.EOF
MyTable.Edit
MyTable.[Selected] = "yes"
MyTable.Update
MyTable.MoveNext
Loop
MyTable.Close
Me![Field0].Requery
Me![Field2].Requery
erhandle:
Resume Next
End Function
List Box:
-----------------------------
Name: Field0
RowSourceType: Table/Query
RowSource: Select Yes
OnDblClick: =Add()
List Box:
-----------------------------
Name: Field2
RowSourceType: Table/Query
RowSource: Select No
OnDblClick: =Del()
Command Button:
--------------------
Name: Button One
Caption: Clear
OnClick: =Clear()
Command Button:
--------------------
Name: Button Two
Caption: Add Item
OnClick: =Add()
Command Button:
-----------------------
Name: Button Three
Caption: Delete Item
OnClick: =Del()
Additional query words: combo fill
Keywords: kbhowto kbusage KB132137