R
ryan.fitzpatrick3
I have this code which I copied and pasted from allen browns search
example database. I changed the tbox code to reflect my code. When I
run the query it gives me a type mismatch error, any one know why?
Here's allen brown's code: (I deleted the some of the other code that
doesn't pertain.)
Private Sub cmdFilter_Click()
'Purpose: Build up the criteria string form the non-blank search
boxes, and apply to the form's Filter.
'Notes: 1. We tack " AND " on the end of each condition so you
can easily add more search boxes; _
we remove the trailing " AND " at the end.
' 2. The date range works like this: _
Both dates = only dates between (both
inclusive. _
Start date only = all dates from this one
onwards; _
End date only = all dates up to (and
including this one).
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria
string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for
dates in a JET query string.
'Date field example. Use the format string to add the # delimiters
and get the right international format.
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([EnteredOn] >= " & Format
(Me.txtStartDate, conJetDate) & ") AND "
End If
'Another date field example. Use "less than the next day" since
this field has times as well as dates.
If Not IsNull(Me.txtEndDate) Then 'Less than the next day.
strWhere = strWhere & "([EnteredOn] < " & Format(Me.txtEndDate
+ 1, conJetDate) & ") AND "
End If
End Sub
Here is my code:
Private Sub cmdFilter_Click()
Dim strdoc As String
strdoc = "qryMakeTableQuickOrder"
DoCmd.Requery
'Purpose: Build up the criteria string form the non-blank search
boxes, and apply to the form's Filter.
'Notes: 1. We tack " AND " on the end of each condition so you
can easily add more search boxes; _
we remove the trailing " AND " at the end.
' 2. The date range works like this: _
Both dates = only dates between (both
inclusive. _
Start date only = all dates from this one
onwards; _
End date only = all dates up to (and
including this one).
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria
string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for
dates in a JET query string.
'Date field example. Use the format string to add the # delimiters
and get the right international format.
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([po_recpt_recdt] >= " & Format
(Me.txtStartDate, conJetDate) & ") AND "
End If
'Another date field example. Use "less than the next day" since
this field has times as well as dates.
If Not IsNull(Me.txtEndDate) Then 'Less than the next day.
strWhere = strWhere & "([po_recpt_recdt] < " & Format
(Me.txtEndDate + 1, conJetDate) & ") AND "
End If
End Sub
Why am I getting a type mismatch error?
example database. I changed the tbox code to reflect my code. When I
run the query it gives me a type mismatch error, any one know why?
Here's allen brown's code: (I deleted the some of the other code that
doesn't pertain.)
Private Sub cmdFilter_Click()
'Purpose: Build up the criteria string form the non-blank search
boxes, and apply to the form's Filter.
'Notes: 1. We tack " AND " on the end of each condition so you
can easily add more search boxes; _
we remove the trailing " AND " at the end.
' 2. The date range works like this: _
Both dates = only dates between (both
inclusive. _
Start date only = all dates from this one
onwards; _
End date only = all dates up to (and
including this one).
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria
string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for
dates in a JET query string.
'Date field example. Use the format string to add the # delimiters
and get the right international format.
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([EnteredOn] >= " & Format
(Me.txtStartDate, conJetDate) & ") AND "
End If
'Another date field example. Use "less than the next day" since
this field has times as well as dates.
If Not IsNull(Me.txtEndDate) Then 'Less than the next day.
strWhere = strWhere & "([EnteredOn] < " & Format(Me.txtEndDate
+ 1, conJetDate) & ") AND "
End If
End Sub
Here is my code:
Private Sub cmdFilter_Click()
Dim strdoc As String
strdoc = "qryMakeTableQuickOrder"
DoCmd.Requery
'Purpose: Build up the criteria string form the non-blank search
boxes, and apply to the form's Filter.
'Notes: 1. We tack " AND " on the end of each condition so you
can easily add more search boxes; _
we remove the trailing " AND " at the end.
' 2. The date range works like this: _
Both dates = only dates between (both
inclusive. _
Start date only = all dates from this one
onwards; _
End date only = all dates up to (and
including this one).
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria
string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for
dates in a JET query string.
'Date field example. Use the format string to add the # delimiters
and get the right international format.
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([po_recpt_recdt] >= " & Format
(Me.txtStartDate, conJetDate) & ") AND "
End If
'Another date field example. Use "less than the next day" since
this field has times as well as dates.
If Not IsNull(Me.txtEndDate) Then 'Less than the next day.
strWhere = strWhere & "([po_recpt_recdt] < " & Format
(Me.txtEndDate + 1, conJetDate) & ") AND "
End If
End Sub
Why am I getting a type mismatch error?