I have been working on a project as a volunteer crime analyst, and I have run into issues on how to enter in multiple text boxes, a multi-valued combo box and how to make sure that if there are no entries made that those boxes are ignored in favor of those that have values in them. I have figured out how to have multiple multi-select list boxes return data from a data entry table, what I'm asking is for help on how to add in the rest of the components that are on the MS Access form that I have for a prototype database.
Here is my code, would like to have some advice on how and where the code for the text boxes and multi-valued combo box would go
Private Sub Command62_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strCriteria1 As String
Dim strCriteria2 As String
Dim strCriteria3 As String
Dim strCriteria4 As String
Dim strCriteria5 As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryMultiselect")
For Each varItem In Me!District.ItemsSelected
strCriteria = strCriteria & ",'" & Me!District.ItemData(varItem) & "'"
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything in the Contract field." _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
For Each varItem In Me!MOMethodofEntry.ItemsSelected
strCriteria1 = strCriteria1 & ",'" & Me!MOMethodofEntry.ItemData(varItem) &
"'"
Next varItem
If Len(strCriteria1) = 0 Then
MsgBox "You did not select anything in the Name field." _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria1 = Right(strCriteria1, Len(strCriteria1) - 1)
For Each varItem In Me!MOLocation.ItemsSelected
strCriteria2 = strCriteria2 & ",'" & Me!MOLocation.ItemData(varItem) & "'"
Next varItem
If Len(strCriteria2) = 0 Then
MsgBox "You did not select anything in the Name field." _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria2 = Right(strCriteria2, Len(strCriteria2) - 1)
For Each varItem In Me!MOPointofEntry.ItemsSelected
strCriteria3 = strCriteria3 & ",'" & Me!MOPointofEntry.ItemData(varItem) &
"'"
Next varItem
If Len(strCriteria3) = 0 Then
MsgBox "You did not select anything in the Name field." _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria3 = Right(strCriteria3, Len(strCriteria3) - 1)
For Each varItem In Me!CircumstanceCode.ItemsSelected
strCriteria4 = strCriteria4 & ",'" & Me!CircumstanceCode.ItemData(varItem) &
"'"
Next varItem
If Len(strCriteria4) = 0 Then
MsgBox "You did not select anything in the Name field." _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria4 = Right(strCriteria4, Len(strCriteria4) - 1)
For Each varItem In Me!MOWeapon.ItemsSelected
strCriteria5 = strCriteria5 & ",'" & Me!MOWeapon.ItemData(varItem) & "'"
Next varItem
If Len(strCriteria5) = 0 Then
MsgBox "You did not select anything in the Contract field." _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria5 = Right(strCriteria5, Len(strCriteria5) - 1)
strSQL = "SELECT * FROM tblDataEntry " & _
"WHERE tblDataEntry.District IN(" & strCriteria & ") AND
tblDataEntry.MOMethodofEntry IN(" & strCriteria1 & ") AND
tblDataEntry.MOLocation IN(" & strCriteria2 & ") AND
tblDataEntry.MOPointofEntry IN (" & strCriteria3 & ") AND
tblDataEntry.CircumstanceCode IN (" & strCriteria4 & ") AND
tblDataEntry.MOWeapon IN(" & strCriteria5 & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryMultiselect"
Set db = Nothing
Set qdf = Nothing
End Sub
Also please let me know if I am doing anything wrong. Still a little new to this.