Someone is going to come along and suggest that you not use the ActiveX Calendar control that comes with Access, because of problems that it can cause, and suggesting some non-ActiveX calendars that you can use instead. Whether ActiveX Calendars cause problems really depends on your use of it. An ActiveX Calendar is fine
if you're not distributing this database among numerous PCs,
or if you are, that all the PCs are running the same version of Access as the PC the app is being developed in runs. Different versions of Access have different versions of the Calendar controls, and mixing them can sometimes cause problems. The same rule exists if you have any idea that you will be upgrading to a later version of Access. The code below will work with whichever type of calendar you use:
What I do for this type of thing is place a calendar control on the form, positioned as you like and set it's
Visible Property to
NO.
Then, using the
DoubleClick property of your text box, have the calendar "popup" for date selection. You'll need to replace
YourCalendarName with the actual name of your calendar, and
YourTextBoxName with the actual name of your text box. You can do this for as many textboxes as you want, using the first bit of code below.
- Private Sub YourTextBoxName_DblClick(Cancel As Integer)
-
YourCalendarName.Visible = True
-
End Sub
-
- Private Sub YourCalendarName_Click()
-
Screen.PreviousControl = YourCalendarName.Value
-
YourTextBoxName.SetFocus
-
YourCalendarName.Visible = False
-
End Sub
-
-
Now, all your user has to do is
DoubleClick on the text box that will hold the date and up pops the calendar! When the user clicks on the date, the calendar disappears and the text box is populated with the date.
Linq
;0)>