View Full Version : Restriction clause for date


sarahjul
03-01-2002, 08:23 AM
I have looked throughout the forum but have not been able to find anything on this.

I need to have user enter date on a table (no problem)but use this date to specify records on that date and back to the beginning of that same month. I am unsure on where to start with this...can someone kick me in the right direction?

David R
03-01-2002, 09:56 AM
Not quite sure if I understand your question correctly, so I'm going to give two answers. Use whichever you need and place the other in the flowerpot.
1) If you mean to restrict your user to entering dates from the current month only, use this in your Form Control's Validation Rule: Month([DateField])=Month(Date()) And Year([DateField])=Year(Date())
And place an appropriate message in the validation text. Something like "Please enter a date in the current month."
2) If you mean to use that field (unbound, I'm guessing?) to pull up a query for the current month only, use something along these lines:
DoCmd.OpenForm "FormName",,,"Month([StoredDateField]) = " & Month([UnboundDateField]) & _
" And Year([StoredDateField]) = " & Year([UnboundDateField])

You might have to enclose them in literal "#" symbols to get them to work, but shouldn't if the field is formatted correctly.

HTH,
David R