Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calendar control and after update event

Status
Not open for further replies.

mikeba1

Programmer
Jan 2, 2005
235
0
0
GB
HI guys
ver 2010
I have a form with a date field with the calendar control.
The after update event simply uses msg to show the value in the date field.
If I select a date from the calendar the msg shows nothing , although the field on the form is correct

If I enter the date everything works.

Can anyone explain ??

Thanks in advance
 
You may need to use a different event. I recall setting the value with VBA code also doesn't trigger the After Update event.

Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016
 
Just had a thought.
When you enter the date of course you see it and hit enter.
With the calendar control you see it on the form and its only when you go to another control is then updated.
It might have to be the next control that executes the code.
 
The OnChange might work but it would fire on every keystroke from a user which would be annoying if you add a msgbox.

Code:
Private Sub StartDate_Change()
    If IsDate(Me.StartDate.Text) And Len(Me.StartDate.Text) > 7 Then [COLOR=#4E9A06]'maybe some other checks[/color]
        MsgBox "On Change"
    End If
End Sub

Private Sub StartDate_LostFocus()
    MsgBox "Lost Focus"
End Sub

What's the purpose for the code?

Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016
 
The code was to check the date with previous data.
The problem with the date calendar control is that if you select a date it is moved into the form but you still have to hit return.
I will put code elsewhere.

Thanks
 
Actually, unlike many previous ActiveX DatePickers and Form-based calendars, Access does consider the Control to be physically populated when done using the native DatePicker, meaning that all of the Control's associated events, such as the BeforeUpdate event, AfterUpdate event, etc, will fire.

The problem is that a Control's AfterUpdate event doesn't fire until you leave the Control.

One approach would be:

Force the user to use the DatePicker

Code:
Private Sub DateField_KeyDown(KeyCode As Integer, Shift As Integer)
 If KeyCode <> vbKeyTab And KeyCode <> vbKeyReturn Then
  KeyCode = 0
 End If
End Sub

Move to another Control

Code:
Private Sub DateField_Change()
  AnotherControl.SetFocus
End Sub

Execute your code in the Control's AfterUpdate event

Code:
Private Sub DateField_AfterUpdate()
 ' Place the desired code here
End Sub

You need to replace DateField and AnotherControl with names of your actual Controls. And since the user can no longer enter the date, freehand, as it were, using the OnChange event won't fire repeatedly, showing the Messagebox over and over again.

Linq ;0)>


Hope this helps!

There's always more than one way to skin a cat!

All posts/responses based on Access 2003/2007
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top