Access - Calendar Control - popup event
I'm trying to use a calendar in Access 2003 to enter data in data fields.
I found a site that showed how to write the code so it will popup when you click on the date field and then disappear when you select the date from the calendar.
I got it working but I want to be able to access that same calendar for other date fields on the form.
So I used a variable call 'originator' to pass the originators name to the variable.
Only thing is...now it doesn't work. I get a type mismatch error and I don't know why. It's exactly the same as the example I found(obviously with my names substituted in).
Please help. (dob is the field I want the date to go into and Calendar6 is the name of the calendar I'm using.) Here's my code:
Option Compare Database
Option Explicit
Dim originator As ComboBox
Private Sub dob_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set originator = dob
Calendar6.Visible = True
Calendar6.SetFocus
If Not IsNull(originator) Then
Calendar6.Value = originator.Value
Else
Calendar6.Value = Date
End If
End Sub
Private Sub Calendar6_Click()
originator.Value = Calendar6.Value
originator.SetFocus
Calendar6.Visible = False
Set originator = Nothing
End Sub
Re: Access - Calendar Control - popup event
isn't dob a textbox ---- originator is classed as a combobox?
shouldn't originator be classed as a control?
Re: Access - Calendar Control - popup event
so you think try putting
'dim originator as textbox'
or
'dim originator as control'
?
I'll try them when I get home from work.
Re: Access - Calendar Control - popup event
headsbout2burst
I have a similar feature in one of my access applics. I got it from a website somewhere i dont remember. It uses a module for poping-up the calendar. It works with the on_click event of the textbox or of a little button next to your date txtbox - as you choose to make it in fact.
It works abs fine. I can upload it all in a small sample db here if ever you cant resolve your current error.
Good luck
Re: Access - Calendar Control - popup event
Code:
dim originator as control
Then you can put either textbox of combobox - I assume you are setting the .text property (VB) or the .value property (vba).
Give it a go and see if it does anything.
Re: Access - Calendar Control - popup event
yes, dim originator as control works.
but now its not inputting the date you select from the calendar, just puts in todays date!! bizzarre...any ideas why?
here's my revised code:
Code:
Option Compare Database
Option Explicit
Dim originator As Control
Private Sub dob_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set originator = dob
Calendar6.Visible = True
Calendar6.SetFocus
If Not IsNull(originator) Then
Calendar6.Value = originator.Value
Else
Calendar6.Value = Date
End If
End Sub
Private Sub Calendar6_Click()
originator.Value = Calendar6.Value
originator.SetFocus
Calendar6.Visible = False
Set originator = Nothing
End Sub
Re: Access - Calendar Control - popup event
I've done it. thanks for your help.
don't know what was wrong, I just deleted everything and started again. worked this time.