A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

date controls



 
 
Thread Tools Display Modes
  #1  
Old October 11th, 2007, 05:16 PM posted to microsoft.public.access.forms
Alan
external usenet poster
 
Posts: 459
Default date controls

Hello,

I have a date field ona form that I'm trying to prevent the user from
entering dates in the past.

On the AfterUpdate event I wrote the following code as a warning message if
they pick a date older than current:

Private Sub pkgShip_AfterUpdate()

If Me.pkgShip Now() Then
MsgBox ("You cannot select a date in the past. Please select another
date.")
Else
End If

End Sub

However nothing seems to happen if I enter dates in the past. Is this not
the way to do it or am I writing this statement incorrectly?

Thanks.

Al
  #2  
Old October 11th, 2007, 05:28 PM posted to microsoft.public.access.forms
Ken Snell \(MVP\)
external usenet poster
 
Posts: 2,506
Default date controls

Use the BeforeUpdate event of the control:

Private Sub pkgShip_BeforeUpdate(Cancel As Integer)

If DateValue(Me.pkgShip) Date() Then
MsgBox "You cannot select a date in the past. Please select another
date.", vbExclamation, "Old Date!"
Cancel = True
End If

End Sub


--

Ken Snell
MS ACCESS MVP



"Alan" wrote in message
...
Hello,

I have a date field ona form that I'm trying to prevent the user from
entering dates in the past.

On the AfterUpdate event I wrote the following code as a warning message
if
they pick a date older than current:

Private Sub pkgShip_AfterUpdate()

If Me.pkgShip Now() Then
MsgBox ("You cannot select a date in the past. Please select
another
date.")
Else
End If

End Sub

However nothing seems to happen if I enter dates in the past. Is this not
the way to do it or am I writing this statement incorrectly?

Thanks.

Al



  #3  
Old October 11th, 2007, 05:40 PM posted to microsoft.public.access.forms
Alan
external usenet poster
 
Posts: 459
Default date controls

That worked great!

Thanks!

Al

"Ken Snell (MVP)" wrote:

Use the BeforeUpdate event of the control:

Private Sub pkgShip_BeforeUpdate(Cancel As Integer)

If DateValue(Me.pkgShip) Date() Then
MsgBox "You cannot select a date in the past. Please select another
date.", vbExclamation, "Old Date!"
Cancel = True
End If

End Sub


--

Ken Snell
MS ACCESS MVP



"Alan" wrote in message
...
Hello,

I have a date field ona form that I'm trying to prevent the user from
entering dates in the past.

On the AfterUpdate event I wrote the following code as a warning message
if
they pick a date older than current:

Private Sub pkgShip_AfterUpdate()

If Me.pkgShip Now() Then
MsgBox ("You cannot select a date in the past. Please select
another
date.")
Else
End If

End Sub

However nothing seems to happen if I enter dates in the past. Is this not
the way to do it or am I writing this statement incorrectly?

Thanks.

Al




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:42 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.