Date Range Search

A

avarusbrightfyre

I have a form that has several text boxes for users to enter criteria for a
search. Each type of search has a separate button that opens a search form
based on criteria in the text boxes (yes, I used the wizard). This all works
fine, except for my date range search, because the wizard doesn't offer an
option to use the "between" function. I would imagine the button should work
fine if I use it and just go into the code builder and replace the criteria
portion of the code to filter out the records between the "me.FromDate" and
"me.ToDate" text boxes. The problem is that none of the standard operators
seem to work in the criteria portion of the code. Does anyone know what the
proper format is? Here is what I have so far:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Search Form"

DoCmd.OpenForm stDocName, , , Between #me.FromDate# and #me.ToDate#

Trying to use this format highlights the first # and gives me an "Expected
end of Statement" compile error.

What is the proper way to program this?
 
D

Duane Hookom

Try:
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Search Form"
stLinkCriteria = "[YourDateField] Between #" & Me.FromDate & "# and #" &
Me.ToDate & "#"
DoCmd.OpenForm stDocName, , , stLinkCriteria

This assumes your dates are in the format m/d/y.
 
D

De Jager

avarusbrightfyre said:
I have a form that has several text boxes for users to enter criteria for a
search. Each type of search has a separate button that opens a search
form
based on criteria in the text boxes (yes, I used the wizard). This all
works
fine, except for my date range search, because the wizard doesn't offer an
option to use the "between" function. I would imagine the button should
work
fine if I use it and just go into the code builder and replace the
criteria
portion of the code to filter out the records between the "me.FromDate"
and
"me.ToDate" text boxes. The problem is that none of the standard
operators
seem to work in the criteria portion of the code. Does anyone know what
the
proper format is? Here is what I have so far:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Search Form"

DoCmd.OpenForm stDocName, , , Between #me.FromDate# and #me.ToDate#

Trying to use this format highlights the first # and gives me an "Expected
end of Statement" compile error.

What is the proper way to program this?
 

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