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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a Date Field Using a Calendar Control

Status
Not open for further replies.

instructorgirl

Instructor
Mar 14, 2005
40
US
I have added a Calendar Control 11.0 to my form. My calendar control is called IssueDateCalendar and it's control source is attached to the dtmIssueDate text box. I have been trying to figure out how to automatically update the dtmIssueDate field on the form when a new date is selected in the calendar. I have looked at several posted answers and I'm still not getting it to work. Any ideas would be greatly appreciated. Thanks!
 
In design view, click on your calendar control. Do Alt+F11 to enter VBA.
Type in:

Sub SyncControls()
Me![dtmIssueDate].Value = Me![IssueDateCalendar]
End Sub

At the top of your VBA window, you will see two dropdowns. The first shows the name of your controls. Click this and select your calendar name (IssueDateCalendar). The next dropdown shows events. Click this and select AfterUpdate. Type in SyncControls between the Private Sub and End Sub statements.
Also place it on the Onload Event of your form.

Now when your from opens, it'll have today's date there and will change when a new date is selected.
 
Forgot to mentioned that the calendar control should have no control source. Make sure it's blank.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top