Here is an example:
Code:
Option Compare Database
Option Explicit
Private Sub btnPlaceHold_Click()
On Error GoTo ErrHandler
Dim db As DAO.Database
Dim qry As String
Dim fkeys As String
fkeys = SQL_Criteria(Me.lstWorkOrder)
If fkeys = "Like '*' " Then
MsgBox "The listbox has no selections"
ElseIf Me.txtComments = "" Then
MsgBox "The comment box is empty"
Else
qry = "UPDATE tblIncomingJobJoin SET Hold=True, Comments=""" & Me.txtComments & """ WHERE ID " & fkeys & ";"
Set db = CurrentDb
db.Execute qry
'Debug.Print qry
Clear_MultiSelect Me.lstWorkOrder
Me.txtComments = ""
MsgBox "Done!"
End If
ExitHandler:
Set db = Nothing
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume ExitHandler
End Sub
Function SQL_Criteria(lstbox As Control) As String
'Build Where Condition for SQL Statement (Bound Column - Numerica data type)
'http://www.myaccesstips.com/functionality/multiselect.html
Dim varItm As Variant
Dim ctl As Control
Dim strCriteria As String
Set ctl = lstbox
For Each varItm In ctl.ItemsSelected
'Use the ItemData Property to select the Bound Column
'Use the Column Property to specify the Row, Column
strCriteria = strCriteria + ctl.ItemData(varItm) & ","
Next varItm
If strCriteria = "" Then
SQL_Criteria = "Like '*' "
Else
SQL_Criteria = "IN(" & Left(strCriteria, Len(strCriteria) - 1) & ")"
'Rremove last comma
End If
End Function
Sub Clear_MultiSelect(lstbox As Control)
'Clears all values Selected in a listbox
'http://www.myaccesstips.com/functionality/multiselect.html
Dim varItm As Variant
Dim ctl As Control
Set ctl = lstbox
For Each varItm In ctl.ItemsSelected
ctl.Selected(varItm) = False
Next varItm
End Sub
http://www.myaccesstips.com/function...ltiselect.html