By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,124 Members | 2,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,124 IT Pros & Developers. It's quick & easy.

Access 2003: Date restrictions

P: 23
Hi guys,

I have a couple of questions about date restrictions.
On one of my forms in my DB I have the MS calendar. The question I have is how do I prevent the user from selecting a date in past and from selecting no more than 45 days into the future. Example today is 12/08/06, I would like to prevent the user from selecting 12/07/06 and unable to select anything pass 01/22/06. Hope that makes sense.

Second part of my questions is I have another form which the source is from a table. In this table there is field which contains dates. The dates are appointments that are setup. On this form you are able to see the appointments from the past and those that are scheduled in the future. I would to restrict the form from showing appointments in the future. If the form is accessed today I would like for it to only show appointments for today and those in the past.
Any help or reference anyone can provide would be greatly appreciated.
Dec 8 '06 #1
Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,616
I have a couple of questions about date restrictions.
On one of my forms in my DB I have the MS calendar. The question I have is how do I prevent the user from selecting a date in past and from selecting no more than 45 days into the future. Example today is 12/08/06, I would like to prevent the user from selecting 12/07/06 and unable to select anything pass 01/22/06. Hope that makes sense.
In the BeforeUpdate event of the control put in some code that checks the control is between today and today +45.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CtrlName_BeforeUpdate(Cancel As Integer
  2.     If Me.CtrlName < Date() _
  3.     Or Me.CtrlName > Date() + 45 Then
  4.         Call MsgBox("Invalid Date")
  5.         Cancel = True
  6.     End If
  7. End Sub)
Second part of my questions is I have another form which the source is from a table. In this table there is field which contains dates. The dates are appointments that are setup. On this form you are able to see the appointments from the past and those that are scheduled in the future. I would to restrict the form from showing appointments in the future. If the form is accessed today I would like for it to only show appointments for today and those in the past.
Any help or reference anyone can provide would be greatly appreciated.
Set record source of the form to
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [table] WHERE [yourdatefield] <= Date()
Dec 8 '06 #2

P: 23
Thank you NeoPa, it worked!
Dec 11 '06 #3

NeoPa
Expert Mod 15k+
P: 31,616
Thank you NeoPa, it worked!
No Probs (Don't sound so surprised).
Dec 11 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.