Allen Browne - Searching between two dates

G

Guest

I have used Allen Brownes search form to create one for myself and it works
swimmingly except the date search. I want to include two unbound text boxes
for searching dates (from and to). Is it just me or does the example database
not include the code for doing such a task. Just help with a pointer in the
right direction of how to write the code for this search would be helpful.

Thanks
 
G

Guest

I have managed to figure out how to get the form to search for one particular
date but how would i get a search form to search between two dates. The
following code was supplied on the example...

'Date field example. Use the format string to add the # delimiters and get
the right international format.

If Not IsNull(Me.txtEntryFrom) Then
strWhere = "([Entry Date] >= " & Format(Me.txtEntryFrom, conJetDate)
& ") AND "
End If

If Not IsNull(Me.txtEntryTo) Then
strWhere = "([Entry Date] >= " & Format(Me.txtEntryTo, 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.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "You did not enter any search
criteria."
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
 

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