I have added a drop down that selects values from a separate table to filter search results. I can't see how to fit the drop down into the current procedure. Also the drop down does not need to be selected every time - just when the user wants to. Any help is appreciated.
Private Sub cmdRunQuery_Click()
If Me.lstFieldList.ItemsSelected.Count = 0 Then
MsgBox "Select some field names first."
Dim qDef As Object
Dim SQL As String
Dim vItem As Variant
' loop through selected field names
For Each vItem In Me.lstFieldList.ItemsSelected
SQL = SQL & ",[" & Me.lstFieldList.ItemData(vItem) & "]"
' build new SQL statement
SQL = "Select " & Mid(SQL, 2) & " from [F442audt]"
SQL = SQL & " Where [D_Date] Between [Begin Date] and [End Date]"
' save query with new SQL statement
Set qDef = CurrentDb.QueryDefs("qryF442audt")
qDef.SQL = SQL
Set qDef = Nothing
' run query