I can't seem to get my brain around this:
I have a simple calendar that, of course, I found here, that I want to use on three different forms. I have it working on one as long as I just want the dates to be entered on that particular form, but am assuming that, in order to use it in multiple forms I need to create a module. I tried the following in a module but get an error when selecting the date in pop up calendar on my form.
Sub ShowCalendar(ByRef DateCompleted As TextBox)
On Error GoTo Err_ShowCalendar
Dim frmCal As Form ' calendar form
Dim ctlD As Control ' date control on this form
Set ctlD = DateCompleted
DoCmd.OpenForm "Calendar", , , , , acDialog
Set frmCal = Forms("Calendar")
With frmCal
Set .DateControl = ctlD
.InitialDate = ctlD.Value
.Visible = True
End With
Exit_ShowCalendar:
Exit Sub
Err_ShowCalendar:
MsgBox Err.Description, vbCritical, "Error #" & Err.Number
Resume Exit_ShowCalendar
End Sub
Code for command button onclick event:
Private Sub Calendar_Click()
DateCompleted = Nz(DateCompleted, Date)
Call ShowCalendar(DateCompleted)
End Sub
This gives me the message "...can't find the form 'Calendar' referred to in a macro or expression or Visual Basic Code"
Any time I am using the calendar, the Date will go into the same table and same field "DateCompleted", just in different situations.
Any help would be appreciated!
Thanks,
Toni
I have a simple calendar that, of course, I found here, that I want to use on three different forms. I have it working on one as long as I just want the dates to be entered on that particular form, but am assuming that, in order to use it in multiple forms I need to create a module. I tried the following in a module but get an error when selecting the date in pop up calendar on my form.
Sub ShowCalendar(ByRef DateCompleted As TextBox)
On Error GoTo Err_ShowCalendar
Dim frmCal As Form ' calendar form
Dim ctlD As Control ' date control on this form
Set ctlD = DateCompleted
DoCmd.OpenForm "Calendar", , , , , acDialog
Set frmCal = Forms("Calendar")
With frmCal
Set .DateControl = ctlD
.InitialDate = ctlD.Value
.Visible = True
End With
Exit_ShowCalendar:
Exit Sub
Err_ShowCalendar:
MsgBox Err.Description, vbCritical, "Error #" & Err.Number
Resume Exit_ShowCalendar
End Sub
Code for command button onclick event:
Private Sub Calendar_Click()
DateCompleted = Nz(DateCompleted, Date)
Call ShowCalendar(DateCompleted)
End Sub
This gives me the message "...can't find the form 'Calendar' referred to in a macro or expression or Visual Basic Code"
Any time I am using the calendar, the Date will go into the same table and same field "DateCompleted", just in different situations.
Any help would be appreciated!
Thanks,
Toni