B
BenNeedHelp
I am very very new to writing visual basic code and I am trying to make my
search button work like the one in the sample Issues Database. There are
unbound text and combo boxes in the detail section of the form where the user
should be able to key in the data they want to search by. Clicking on the
search button should open a subform in the footer section of the form
displaying the records that fit the search criteria entered in the unbound
boxes. I am getting the following error message: Run-time error '3075':
syntax error(missing operator) in query expression '1+1 AND Mail Log.[Opened
by] Parker, John".
I don't know how to fix the problem. The code that I am using is below.
Any suggestions would be greatly appreciated.
Private Sub Search_Click()
Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
' If Date Received From
If IsDate(Me.DateReceivedFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Mail Log.[Date Received] >= " &
GetDateFilter(Me.DateReceivedFrom)
ElseIf Nz(Me.DateReceivedFrom) <> "" Then
strError = cInvalidDateError
End If
' If Date Received To
If IsDate(Me.DateReceivedTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Mail Log.[Date Received] <= " &
GetDateFilter(Me.DateReceivedTo)
ElseIf Nz(Me.DateReceivedTo) <> "" Then
strError = cInvalidDateError
End If
' If Opened by
If Nz(Me.Openedby) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Mail Log.[Opened by] = " &
Me.Openedby & "'"
End If
' If Case Name
If Nz(Me.CaseName) <> "" Then
'Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "Mail Log.[Case Name] = " &
Me.CaseName & "'"
End If
' If Case Number
If Nz(Me.CaseNumber) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Mail Log.[Case Number] = '" &
Me.CaseNumber & "'"
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse Mail", acFormDS, , strWhere, acFormEdit,
acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.Browse_Mail.Form.Filter = strWhere
Me.Browse_Mail.Form.FilterOn = True
End If
End Sub
search button work like the one in the sample Issues Database. There are
unbound text and combo boxes in the detail section of the form where the user
should be able to key in the data they want to search by. Clicking on the
search button should open a subform in the footer section of the form
displaying the records that fit the search criteria entered in the unbound
boxes. I am getting the following error message: Run-time error '3075':
syntax error(missing operator) in query expression '1+1 AND Mail Log.[Opened
by] Parker, John".
I don't know how to fix the problem. The code that I am using is below.
Any suggestions would be greatly appreciated.
Private Sub Search_Click()
Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
' If Date Received From
If IsDate(Me.DateReceivedFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Mail Log.[Date Received] >= " &
GetDateFilter(Me.DateReceivedFrom)
ElseIf Nz(Me.DateReceivedFrom) <> "" Then
strError = cInvalidDateError
End If
' If Date Received To
If IsDate(Me.DateReceivedTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Mail Log.[Date Received] <= " &
GetDateFilter(Me.DateReceivedTo)
ElseIf Nz(Me.DateReceivedTo) <> "" Then
strError = cInvalidDateError
End If
' If Opened by
If Nz(Me.Openedby) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Mail Log.[Opened by] = " &
Me.Openedby & "'"
End If
' If Case Name
If Nz(Me.CaseName) <> "" Then
'Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "Mail Log.[Case Name] = " &
Me.CaseName & "'"
End If
' If Case Number
If Nz(Me.CaseNumber) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Mail Log.[Case Number] = '" &
Me.CaseNumber & "'"
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse Mail", acFormDS, , strWhere, acFormEdit,
acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.Browse_Mail.Form.Filter = strWhere
Me.Browse_Mail.Form.FilterOn = True
End If
End Sub