Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub ComittRecord_Click()
Dim lst As ListBox
Dim varItem As Variant
Dim strIN as String, strSQL as String, strQ as String
strQ = Chr$(34)
If lst.MultiSelect > 0 Then
If lst2.ItemsSelected.Count > 0 Then
For Each varItem2 In lst.ItemsSelected
strIn = strIn & " " & lst.ItemData(varItem)
Next varItem2
End If
End If
If Len(strIn) > 0 Then
strSQL = "SELECT * from YourTable Where YourTestField IN " _
& strQ & Trim(strIn) & strQ
'You can now use this SQL statement as a record source or
'YourFieldorSubForm.RecordSource = strSQL type of thing
'or for DAO or ADO or a QueryDef.
Else
Msgbox "Please select something from the listbox first", vbOkOnly
End If
End Sub
Function BuildWhereClause(frm As Form) As String
'********************************
'* Declaration Specifications *
'********************************
Dim ctl As Control
Dim varItem As Variant
Dim strAnd As String
Dim strField As String
Dim strFilter As String
Dim strType As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
On Error GoTo ErrHandler
'****************
'* Initialize *
'****************
strFilter = vbNullString
strAnd = vbNullString
'*********************************************************
'* Loop thru all controls on form to find list box(es) *
'*********************************************************
For Each ctl In frm.Controls
If (ctl.ControlType = acListBox) Then
'*************************************************************************************************
'* Should this list box be processed? *
'* If so, then tag property contains the name of the table and field and the type of the field *
'* (Structure of tag property: Where=TableName.FieldName,DataType, ) *
'* NOTE that the code assumes the tag property is structured properly *
'*************************************************************************************************
If ((ctl.Enabled) And (Not ctl.Locked) And (ctl.ItemsSelected.Count > 0) And (InStr(ctl.Tag, "Where=") > 0)) Then
j = InStr(ctl.Tag, "Where=")
k = InStr(j, ctl.Tag, ",")
strField = Mid(ctl.Tag, j + 6, k - (j + 6))
j = InStr(k + 1, ctl.Tag, ",")
strType = Mid(ctl.Tag, k + 1, j - k - 1)
strFilter = strFilter & strAnd & strField & " In ("
'******************************************
'* Loop thru items selected in list box *
'******************************************
For Each varItem In ctl.ItemsSelected
If (strType = "String") Then
strFilter = strFilter & "'" & ctl.Column(ctl.BoundColumn - 1, varItem) & "', "
ElseIf (strType = "Number") Then
strFilter = strFilter & ctl.Column(ctl.BoundColumn - 1, varItem) & ", "
End If
Next varItem
strFilter = Mid(strFilter, 1, Len(strFilter) - 2) & ") "
strAnd = " AND "
End If
End If
Next
'***********************************
'* Return Where clause to caller *
'***********************************
BuildWhereClause = strFilter
'********************
'* Exit Procedure *
'********************
ExitProcedure:
Exit Function
'****************************
'* Error Recovery Section *
'****************************
ErrHandler:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation
BuildWhereClause = "!!!ERROR!!!"
Resume ExitProcedure
End Function