combobox "cboModel"
Row Source
Expand|Select|Wrap|Line Numbers
- SELECT [tblModel].[ID], [tblModel].[Model] FROM tblModel ORDER BY [Model];
Expand|Select|Wrap|Line Numbers
- SELECT [Query1].[Contact Name] FROM Query1 ORDER BY [Contact Name];
"File AS" and "Contact Name". Each of these fields combines the first and last name into one field. one does it first name last name and the other last name first name.
and then on form1 i have two cmdbuttons "cmdApplyFilter" and "cmdRemoveFilter"
I have tried two differant codes
Here is the 1st code:
Expand|Select|Wrap|Line Numbers
- Option Compare Database
- Option Explicit
- Private Sub cmdApplyFilter_Click()
- Dim strModel As String
- Dim strContactName As String
- Dim strFilter As String
- ' Check that the report is open
- DoCmd.OpenReport "rptContacts", acPreview, , strFilter
- ' Build criteria string for Office field
- If IsNull(Me.cboModel.Value) Then
- strModel = "Like '*'"
- Else
- strModel = "='" & Me.cboModel.Value & "'"
- End If
- ' Build criteria string for Department field
- If IsNull(Me.cboContactName.Value) Then
- strContactName = "Like '*'"
- Else
- strContactName = "='" & Me.cboContactName.Value & "'"
- End If
- ' Combine criteria strings into a WHERE clause for the filter
- strFilter = "[Model] " & strModel & " AND [ContactName] " & strContactName
- ' Apply the filter and switch it on
- With Reports![rptContacts]
- .Filter = strFilter
- .FilterOn = True
- End With
- End Sub
- Private Sub cmdRemoveFilter_Click()
- On Error Resume Next
- ' Switch the filter off
- Reports![rptContacts].FilterOn = False
- End Sub
Here is the seconf code I tried:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdOpenReport_Click()
- Dim strModel As String
- Dim strContactName As String
- Dim strFilter As String
- strFilter = "1=1 "
- ' Build criteria string for Office field
- If Not IsNull(Me.cboModel) Then
- strFilter = " AND [Model] ='" & Me.cboModel.Value & "'"
- End If
- ' Build criteria string for Department field
- If Not IsNull(Me.cboContactName) Then
- strFilter = " AND [Contact Name] ='" & Me.cboContactName.Value & "'"
- End If
- ' Apply the filter and switch it on
- DoCmd.OpenReport "rptContacts", acPreview, , strFilter
- End Sub
Run Time Error '3075':
Syntax error (missing operator) in query expression ' AND [Model]='*620".
Any help please!!