stLinkCriteria between dates

  • Thread starter Thread starter Jen
  • Start date Start date
J

Jen

Hello.
I have two textboxes on a form, one for startdate (txt_tidpunkt_fran) and
one for enddate (txt_tidpunkt_till). Based on this i try to filter a second
form. In the onclick event of the button I have as stLinkCriteria:
stLinkCriteria = "datum= Between " & [Forms]![startform]![txt_tidpunkt_fran]
& " And " & [Forms]![startform]![txt_tidpunkt_till] & ""

but keep getting Syntax error (missing operator) in query expression....

Anyone that knows where I fail?
 
Jen,

Is this all happening on the form "startform"?
Is [datum] a Date/Time datatype field that contains the dates?

Try:
stLinkCriteria = "[datum] Between #" & [txt_tidpunkt_fran] & "# And #" &
[txt_tidpunkt_till] & "#"

The above will become a string, something like:
Datum Between #8/1/2003# and #9/3/2003#

You do not need the forms!formname syntax if this is all on the same form.
You must enclose the criteria dates with the # sign.

See VBA Help
Date and Time;
Date and Time Criteria from a Control on a Form
 
The problem is the equal sign, but also be aware that dates need to be
delimited with # (and they need to be in mm/dd/yyyy format, regardless of
what the short date format is on the user's system).

Try:

stLinkCriteria = "datum Between " & _
Format$([Forms]![startform]![txt_tidpunkt_fran], "\#mm\/dd\/yyyy\#") & _
" And " & Format$([Forms]![startform]![txt_tidpunkt_till],
"\#mm\/dd\/yyyy\#")
 
Works exactly as I wanted, as soon as I removed the _:s (did you put them
there for marking that word wrap wasn't intended?).

Thanks (once again) Doug, -and also thank you Fred for your answer to my
question.

Jen.
 
Yup, they were to avoid word-wrap (although I see I wasn't successful)

--
Doug Steele, Microsoft Access MVP



Jen said:
Works exactly as I wanted, as soon as I removed the _:s (did you put them
there for marking that word wrap wasn't intended?).

Thanks (once again) Doug, -and also thank you Fred for your answer to my
question.

Jen.

Douglas J. Steele said:
The problem is the equal sign, but also be aware that dates need to be
delimited with # (and they need to be in mm/dd/yyyy format, regardless of
what the short date format is on the user's system).

Try:

stLinkCriteria = "datum Between " & _
Format$([Forms]![startform]![txt_tidpunkt_fran], "\#mm\/dd\/yyyy\#")
&
_
" And " & Format$([Forms]![startform]![txt_tidpunkt_till],
"\#mm\/dd\/yyyy\#")
 
Back
Top