Limit date input into query parameters.

  • Thread starter hotrod1952 via AccessMonster.com
  • Start date
H

hotrod1952 via AccessMonster.com

I have a query which I have declared two input parameters. Period Start &
Period End. I am using these dates in a query for payroll information. The
Period start should always be a Monday and the Period End should always be
Sunday as that is our current payroll set-up. When I run the query (the query
works now) I would like to have some kind of error handler set up in case a
date for either is not a Monday or Sunday respectively. For example:

If a Date is entered into the Period Start that is not a Monday I would like
a message box to pop up and say "Re-enter correct date for Monday" And have
the code set up to allow me to re-enter a correct Monday date.
Same for the Period End.

Any Ideas on how to set this up?
 
K

KARL DEWEY

This will not give an error message but will change the date automatically.
Changes date to a Monday --
DateAdd('d',-Format([Period Start],"w")+2,[Period Start])

Changes date to a Monday --
DateAdd('d',-Format([Period End],"w")+1,[Period End])
 
K

Klatuu

If you are allowing the parameters input boxes to pop up when you run the
query, you don't have ant control over what is entered. I you are using a
form to get the parameter values and referencing the form control values in
the query you can use the After Update events of the controls to check the
input.

To check for the Monday:

Dim dtmTheDay As Date
dtmTheDay = CDate(Me.Text0)
If Weekday(dtmTheDay) <> 2 Then
MsgBox "This Date Must Be a Monday"
Cancel = True
End If

Change the compare value to 1 to check for Sunday.
 

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