G
Guest
Hi all,
I'm trying to write some VB code in Access 2002, the user selects data using
a form & when they hit ok it brings up a report displaying all the records
that match.
The form has three combo boxes & two text boxes.
Commercial (combo)
Customer (Combo)
Status (combo)
Beginning Date (txt)
End Date (Txt)
So the user could be really specific & use all of the criteria to narrow
down the records shown by selecting data in all options or just one/two combo
boxes/text boxes.
E.g user selected Commercial 'Angie',
Beginning Date '10/1/2004'
End Date '10/30/2004'
I'm having a problem with a 'Run Time Error 13' 'Type mismatch'. I think it
is something to with declaring the date in my Dim statement.
code:
Option Compare Database
Private Sub CmdApplyfilter_Click()
Dim StrCommercial As String
Dim StrCustomer As String
Dim Date_Due As Date
Dim StrStatus As String
Dim StrFilter As String
Date_Due = Date
'Code to automatically open report
If SysCmd(acSysCmdGetObjectState, acReport, "rptRFQ Receipt to Tender
Sent") <> acObjStateOpen Then
DoCmd.OpenReport "rptRFQ Receipt to Tender Sent", acViewPreview,
StrFilter
End If
'Build Criteria string for Commercial Staff
If IsNull(Me.Cbocommercial.Value) Then
StrCommercial = "Like '*'"
Else
StrCommercial = "='" & Me.Cbocommercial.Value & "'"
End If
'Build Criteria string for Customer
If IsNull(Me.CboCustomer.Value) Then
StrCustomer = "Like '*'"
Else
StrCustomer = "='" & Me.CboCustomer.Value & "'"
End If
'Build criteria for Date due for Beginning Date
If IsNull(Me.txtbegdate.Value) Then
Date_Due = "Like '*'"
Else
Date_Due = "='" & Me.txtbegdate.Value & "'"
End If
'Build criteria for Date due for End Date
If IsNull(Me.txtenddate.Value) Then
Date_Due = "Like '*'"
Else
Date_Due = "='" & Me.txtenddate.Value & "'"
End If
'Build Criteria string for Status
If IsNull(Me.CboStatus.Value) Then
StrStatus = "Like '*'"
Else
StrStatus = "='" & Me.CboStatus.Value & "'"
End If
'Combine criteria strings into WHERE clause for the filter
StrFilter = " [Commercial] " & StrCommercial & " AND [Customer] " &
StrCustomer & " AND [Date Due] " & Date_Due & " AND [Order Status] " &
StrStatus
'Apply the filter and switch on
With Reports![rptRFQ Receipt to Tender Sent]
.Filter = StrFilter
.FilterOn = True
End With
End Sub
Any help would be greatly appreciated!
Thanks in advanced
Michelle
I'm trying to write some VB code in Access 2002, the user selects data using
a form & when they hit ok it brings up a report displaying all the records
that match.
The form has three combo boxes & two text boxes.
Commercial (combo)
Customer (Combo)
Status (combo)
Beginning Date (txt)
End Date (Txt)
So the user could be really specific & use all of the criteria to narrow
down the records shown by selecting data in all options or just one/two combo
boxes/text boxes.
E.g user selected Commercial 'Angie',
Beginning Date '10/1/2004'
End Date '10/30/2004'
I'm having a problem with a 'Run Time Error 13' 'Type mismatch'. I think it
is something to with declaring the date in my Dim statement.
code:
Option Compare Database
Private Sub CmdApplyfilter_Click()
Dim StrCommercial As String
Dim StrCustomer As String
Dim Date_Due As Date
Dim StrStatus As String
Dim StrFilter As String
Date_Due = Date
'Code to automatically open report
If SysCmd(acSysCmdGetObjectState, acReport, "rptRFQ Receipt to Tender
Sent") <> acObjStateOpen Then
DoCmd.OpenReport "rptRFQ Receipt to Tender Sent", acViewPreview,
StrFilter
End If
'Build Criteria string for Commercial Staff
If IsNull(Me.Cbocommercial.Value) Then
StrCommercial = "Like '*'"
Else
StrCommercial = "='" & Me.Cbocommercial.Value & "'"
End If
'Build Criteria string for Customer
If IsNull(Me.CboCustomer.Value) Then
StrCustomer = "Like '*'"
Else
StrCustomer = "='" & Me.CboCustomer.Value & "'"
End If
'Build criteria for Date due for Beginning Date
If IsNull(Me.txtbegdate.Value) Then
Date_Due = "Like '*'"
Else
Date_Due = "='" & Me.txtbegdate.Value & "'"
End If
'Build criteria for Date due for End Date
If IsNull(Me.txtenddate.Value) Then
Date_Due = "Like '*'"
Else
Date_Due = "='" & Me.txtenddate.Value & "'"
End If
'Build Criteria string for Status
If IsNull(Me.CboStatus.Value) Then
StrStatus = "Like '*'"
Else
StrStatus = "='" & Me.CboStatus.Value & "'"
End If
'Combine criteria strings into WHERE clause for the filter
StrFilter = " [Commercial] " & StrCommercial & " AND [Customer] " &
StrCustomer & " AND [Date Due] " & Date_Due & " AND [Order Status] " &
StrStatus
'Apply the filter and switch on
With Reports![rptRFQ Receipt to Tender Sent]
.Filter = StrFilter
.FilterOn = True
End With
End Sub
Any help would be greatly appreciated!
Thanks in advanced
Michelle