Type mismatch

D

davethewelder

Hi, I have a search subform for looking for assessments which are between two
dates. The dates are entered in unbound text boxes, Start date and end date.
When I enter the dates in the textboxes I get an error message "Error 13",
"Type Mismatch".

I have copied the code from a downloaded database Search2000 from Allen
Browne and modified the field name. The field I have added is in another
subform and is called "Assessment Date" and is formatted to Short Date.
Here is the modified code:

I also do not understand the format of the constant conjetDate.

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.
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.Textstartdate) Then
strWhere = strWhere & "([Assessment Date] >= " &
Format(Me.Textstartdate, 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.Textenddate) Then 'Less than the next day.
strWhere = strWhere & "([Assessment Date] < " &
Format(Me.Textenddate + 1, conJetDate) & ") AND "
End If

'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's Filter.
'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ") to
remove.
lningLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the "
AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub


Any help would be appreciated.

Davie
 
B

bismuth83

In the Search2000 sample, the search date textboxes are formatted to
Short Date. Are yours as well? I get your same error when these are
not formatted, but it goes away when a format is assigned.
 
D

davethewelder

bismuth83, that worked fine. Thanks for that. Onward to the next problem :)

Cheers,

Davie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top