I've created a multicriteria search form for a contact management database. Now I would like to have a button on my form that would create a report based on the results of the search (lstresults).
How can I do that ?
Thanks in advance for your help
Here is the code I'm using
Dim SQL As String
Dim SQLWhere As String
SQL = "SELECT OrganisationID, ContactID, FirstName, LastName, EmailName, Title, Board, Communications, Executive, Expert FROM Contacts Where Contacts!ContactID <> 0 "
If Not Me.chkExp Then
SQL = SQL & "And Contacts!Expert like '*" & Me.txtSrchExp & "*' "
End If
If Not Me.chkexec Then
SQL = SQL & "And Contacts!Executive like '*" & Me.txtSrchExec & "*' "
End If
If Not Me.ChkTech Then
SQL = SQL & "And Contacts!Technical like '*" & Me.txtSrchTech & "*' "
End If
If Not Me.chkCom Then
SQL = SQL & "And Contacts!Communications like '*" & Me.TxtSrchCom & "*' "
End If
If Not Me.chkRegul Then
SQL = SQL & "And Contacts!RegulAff like '*" & Me.txtSrchRegul & "*' "
End If
If Not Me.chkPetc Then
SQL = SQL & "And Contacts!Petcore like '*" & Me.txtSrchPetc & "*' "
End If
If Not Me.chkBoard Then
SQL = SQL & "And Contacts!Board like '*" & Me.TxtSrchBoard & "*' "
End If
SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where "
- Len("Where "
+ 1))
SQL = SQL & ";"
Me.lblStats.Caption = DCount("*", "Contacts", SQLWhere) & " / " & DCount("*", "Contacts"
Me.lstResults.RowSource = SQL
Me.lstResults.Requery
End Sub
How can I do that ?
Thanks in advance for your help
Here is the code I'm using
Dim SQL As String
Dim SQLWhere As String
SQL = "SELECT OrganisationID, ContactID, FirstName, LastName, EmailName, Title, Board, Communications, Executive, Expert FROM Contacts Where Contacts!ContactID <> 0 "
If Not Me.chkExp Then
SQL = SQL & "And Contacts!Expert like '*" & Me.txtSrchExp & "*' "
End If
If Not Me.chkexec Then
SQL = SQL & "And Contacts!Executive like '*" & Me.txtSrchExec & "*' "
End If
If Not Me.ChkTech Then
SQL = SQL & "And Contacts!Technical like '*" & Me.txtSrchTech & "*' "
End If
If Not Me.chkCom Then
SQL = SQL & "And Contacts!Communications like '*" & Me.TxtSrchCom & "*' "
End If
If Not Me.chkRegul Then
SQL = SQL & "And Contacts!RegulAff like '*" & Me.txtSrchRegul & "*' "
End If
If Not Me.chkPetc Then
SQL = SQL & "And Contacts!Petcore like '*" & Me.txtSrchPetc & "*' "
End If
If Not Me.chkBoard Then
SQL = SQL & "And Contacts!Board like '*" & Me.TxtSrchBoard & "*' "
End If
SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where "
SQL = SQL & ";"
Me.lblStats.Caption = DCount("*", "Contacts", SQLWhere) & " / " & DCount("*", "Contacts"
Me.lstResults.RowSource = SQL
Me.lstResults.Requery
End Sub