Assign a date to text box by picking a date in the calendar

I am using Access 2003 and I want to do the caption action. However, the date in the text box only stores the initital date of the calendar but when I pick another date in the calendar, the date in the textbox will refresh only after bI click the text box. How do I get the text box refreshed automatically after i pick a date in the calendar? I am using Calendar Control 11.0.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What event are you using to update the TextBox?  You should use the AfterUpdate event:

Private Sub myCalendar_AfterUpdate()

myText = myCalendar.Value

End Sub
howardchingAuthor Commented:
Please note that no such event in calendar control. In addition, even such event exist, the text box will not rehresh automatically.
Try using lebans calendar code.  It uses API calls to the Windows calendar so no need for a control, Is easier to use) more features and more reliable. It also comes with full instructions and examples.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

howardchingAuthor Commented:
No. I want to use the Calendar Control.
>> no such event in calendar control

To get to the AfterUpdate calendar control:

1- Go to the Form module (In Design Mode, View --> Code).
2- Select the Calendar object from the drop-down Object list (the drop-down list to the left above your code).
3- Select "AfterUpdate" from the drop-down Procedures/Events list (the drop-down list to the right above your code).

Alternately, you can just copy-paste the above text into your code. Assuming the name of your text field is myText, selecting a calendar date will update the name of your field automatically.
Donald MaloneyConsultantCommented:
I have an older calendar control

the click event works even tho it doesnt show in the properties.

This displays the selected date using the click event:
Private Sub ActiveXCtl0_click()

Dim valdate As String

valdate = MsgBox("Date click is: " & Me.ActiveControl.OldValue, vbOKOnly, "Show Date")

End Sub
in design right click the object then select calendar  properties and then click help to see what method to use.
Sayad Aziz AhmadAccounts ManagerCommented:
There doesn't exit any event which might update on Click in the control. However you can use Form Current Event and Lost Focus event (calender control) to store vale in ur textbox as follows :

Private Sub Calendar0_LostFocus()
 Me.Text1 = Me.Calendar0.Value
End Sub
Private Sub Form_Current()
 If Me.NewRecord Then
  Me.Text1 = Me.Calendar0.Value
 End If
End Sub

However i will suggest you to use Microsoft Date Time Picker (This will occupy less space on form than the calender control) and would update as you select date.

Sayad Aziz AhmadAccounts ManagerCommented:
mcallarse  suggestion will work to use update event of control from Form module window.


Rey Obrero (Capricorn1)Commented:
if you really want to use calendar control, see this

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I would like to advise you to work with an "all Access calendar" like in the link from thenelsen. (Personally I use the minicalendar from
When you "move" your database to another PC you'll experience why.
The use of ActiveX controls gives a lot of extra hassle and broken references due to missing .ocx or .dll files are giving unpredictable error messages.

Just my 0.02$

Donald MaloneyConsultantCommented:
the click event works even tho it doesnt show in properties.

see my comment
"in design. right click the object, then select calendar  properties, and then click help, to see what method to use."

go to events
The following table describes the events for the Calendar control.

Event      Description
AfterUpdate      Occurs after the user moves to a new date in the Calendar control and after the calendar has been refreshed.
BeforeUpdate      Occurs after the user moves to a new date in the Calendar control but before the calendar has been refreshed.
Click      Occurs when the user clicks a date in the Calendar control.
DblClick      Occurs when the user double-clicks a date in the Calendar control.
KeyDown      Occurs when the user presses a key while the Calendar control has the focus.
KeyPress      Occurs when the user presses and releases an ANSI key while the Calendar control has the focus.
KeyUp      Occurs when the user releases a key while the Calendar control has the focus.
NewMonth      Occurs when the Calendar control date changes to a new month.
NewYear      Occurs when the Calendar control date changes to a new year

Sayad Aziz AhmadAccounts ManagerCommented:

<After Update event also doesn't appear in property sheet>
i have second supported mcallarse since he was the first to offer after update event.

in module there are several events available which is not available in the property sheet ... this was not known to me before.

Donald MaloneyConsultantCommented:

I didn't know that either until I saw a form that used the calendar and the on click event.

Then I looked at the documentation in the help section of the calendar object.

The click event triggers immediately.  The after update triggers after the focus is off the object.
At least this is how it seemed to work for me when I tested it.

howardching is looking, I trhink, to chjange a caption.  It seemed to me that this would occur immediately on clicking a date.

either way and whoever get points isn't important,to me, as long as the questioner gets the answer they want.

Just passing on info that may help.


It would have been nice when you would have elaborated on your choice.
The chosen answer doesn't really fit your question and as a user I would find it really annoying to get a popup when only activating a textbox. Now when tabbing though the textboxes on the form (even when I don't change the value) you need to close the popup calendar.
The normal way will be to have a button to get the calendar activated, allowing you to enter the data manually.

Remains the general .ocx problem that moving the database to another PC without the needed .ocx will give a dump...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.