R
Ralph Wischnewski
I am attempting to set up a screen from which users can select records using
"AND" logic. I am coming up with either "Syntax" or "Type Mismatch" errors
and I can't understand why. The cose so far is shown below. The Selection
form has 3 criteria slection posibilities.
Te first is for "Location ID". this field is in text format and is
producing a "Syntax" Error message: (Missing operator)in query expresion)
The second is a date format set up in the table as "mm-dd-yyyy". On
entering a date in the selection screen I get a "Type MisMatch" error.
The 3rd is a auto number long integer format and also produces a "Type
Mismatch" error.
Can some one help?
This is the code:
Private Sub CmdView_Click()
On Error GoTo Err_CmdView_Click
Dim db As Database
Dim rst As Recordset
'Clear the global Directive filter string
gstrDirView = ""
' and parse out a new one
'*****Set Location ID -------Syntax error
If Not IsNothing(Me!CboLoc) Then
If IsNothing(gstrDirView) Then
gstrDirView = "[LocCust] = " & Me!CboLoc
Else
gstrDirView = gstrDirView & " AND [LocCust] = " & Me!CboLoc
End If
End If
'********Set Date Comparison -----Type Mismatch
If Not IsNothing(Me!FromDate) Then
If IsNothing(gstrDirView) Then
gstrDirView = "[TargetDate] >= " & "#" & Me!FromDate & "#"
Else
gstrDirView = gstrDirView & "AND [TargetDate] >= " & "#" &
Me!FromDate & "#"
End If
End If
'*********Set DirID--------Type Mismatch
If Not IsNothing(Me.CboDirID) Then
If IsNothing(gstrDirView) Then
gstrDirView = "[DirID] = " & Me.CboDirID
Else
gstrDirView = gstrDirView & " AND [DirID] = " & Me.CboDirID
End If
End If
'*********If No criteria, then nothing to do
If IsNothing(gstrDirView) Then
MsgBox "No Criteria Specified.", vbExclamation, "TSSA Directives"
Exit Sub
End If
'********Search based on the string
If IsLoaded("FDirView") Then
Forms!FDirView.SetFocus
DoCmd.ApplyFilter , gstrDirView
Else
Set db = CurrentDb
Set rst = db.OpenRecordset( _
"SELECT DISTINCTROW " & _
"QDirView.DirID " & _
"FROM QDirView " & _
"WHERE " & gstrDirView & ";")
DoCmd.OpenForm "FDirView", acPreview, _
WhereCondition:=gstrDirView
Exit Sub
End If
Exit_CmdView_Click:
Exit Sub
Err_CmdView_Click:
MsgBox Err.Description
Resume Exit_CmdView_Click
End Sub
"AND" logic. I am coming up with either "Syntax" or "Type Mismatch" errors
and I can't understand why. The cose so far is shown below. The Selection
form has 3 criteria slection posibilities.
Te first is for "Location ID". this field is in text format and is
producing a "Syntax" Error message: (Missing operator)in query expresion)
The second is a date format set up in the table as "mm-dd-yyyy". On
entering a date in the selection screen I get a "Type MisMatch" error.
The 3rd is a auto number long integer format and also produces a "Type
Mismatch" error.
Can some one help?
This is the code:
Private Sub CmdView_Click()
On Error GoTo Err_CmdView_Click
Dim db As Database
Dim rst As Recordset
'Clear the global Directive filter string
gstrDirView = ""
' and parse out a new one
'*****Set Location ID -------Syntax error
If Not IsNothing(Me!CboLoc) Then
If IsNothing(gstrDirView) Then
gstrDirView = "[LocCust] = " & Me!CboLoc
Else
gstrDirView = gstrDirView & " AND [LocCust] = " & Me!CboLoc
End If
End If
'********Set Date Comparison -----Type Mismatch
If Not IsNothing(Me!FromDate) Then
If IsNothing(gstrDirView) Then
gstrDirView = "[TargetDate] >= " & "#" & Me!FromDate & "#"
Else
gstrDirView = gstrDirView & "AND [TargetDate] >= " & "#" &
Me!FromDate & "#"
End If
End If
'*********Set DirID--------Type Mismatch
If Not IsNothing(Me.CboDirID) Then
If IsNothing(gstrDirView) Then
gstrDirView = "[DirID] = " & Me.CboDirID
Else
gstrDirView = gstrDirView & " AND [DirID] = " & Me.CboDirID
End If
End If
'*********If No criteria, then nothing to do
If IsNothing(gstrDirView) Then
MsgBox "No Criteria Specified.", vbExclamation, "TSSA Directives"
Exit Sub
End If
'********Search based on the string
If IsLoaded("FDirView") Then
Forms!FDirView.SetFocus
DoCmd.ApplyFilter , gstrDirView
Else
Set db = CurrentDb
Set rst = db.OpenRecordset( _
"SELECT DISTINCTROW " & _
"QDirView.DirID " & _
"FROM QDirView " & _
"WHERE " & gstrDirView & ";")
DoCmd.OpenForm "FDirView", acPreview, _
WhereCondition:=gstrDirView
Exit Sub
End If
Exit_CmdView_Click:
Exit Sub
Err_CmdView_Click:
MsgBox Err.Description
Resume Exit_CmdView_Click
End Sub