LarryDeLaruelle
Technical User
I'm using the ActiveX Calendar control to allow my users to select a beginning report date. Based on that date, I want to set the ending date (usually first to last of month).
I'm still new to ActiveX and I'm not sure how they work. I picked up the code for this from a book and am trying to modify it for my needs.
I tried putting the date manipulation code at the end of the procedure that calls the calendar but it treats the date as it was originally set (on open = Date(); if I leave it empty, I get a Type Mismatch [null?] error when I call frmCalendar). Yet, when frmCalendar closes the date displayed correctly in by text box.
I put the date manipulation code in the txtStart After Update event -- Nothing happens even though the date is updated.
I then tried putting a txtStart.SetFocus at the end of the code which calls frmCalendar and the date manipulation code in the On Got Focus event, guess what? The Set Focus closes my calling form. I'm stumped! Here is the code calling frmCalendar:
Dim frmCal As Form
Dim ctlD As Control
Dim datToday As Date
Set ctlD = Me!txtStart
DoCmd.OpenForm "frmCalendar", , , , , acHidden
Set frmCal = Forms("frmCalendar"
With frmCal
Set .DateControl = ctlD
.InitialDate = ctlD.Value
.Visible = True
End With
Here is the code from frmCalendar:
Option Compare Database
Option Explicit
Private mctlDate As Control
Public Property Set DateControl(ByVal ctlDate As Control)
Set mctlDate = ctlDate
End Property
Public Property Let InitialDate(datD As Date)
Me!ctlCalendar = datD
End Property
Private Sub SetAndClose()
If mctlDate Is Nothing Then
MsgBox "The Date has not been set", , "Calendar Form Error"
Else
mctlDate = ctlCalendar.Value
End If
DoCmd.Close
End Sub
Private Sub ctlCalendar_Click()
SetAndClose
End Sub
Private Sub ctlCalendar_KeyUp(KeyCode As Integer, ByVal Shift As Integer)
Select Case KeyCode
Case vbKeyReturn
SetAndClose
Case vbKeyEscape
DoCmd.Close
End Select
End Sub
Private Sub ctlCalendar_updated(code As Integer)
End Sub
How can I call the calendar and then execute my date commands?
Any help will be appreciated.
Thanks.
Larry De Laruelle
larry1de@yahoo.com
I'm still new to ActiveX and I'm not sure how they work. I picked up the code for this from a book and am trying to modify it for my needs.
I tried putting the date manipulation code at the end of the procedure that calls the calendar but it treats the date as it was originally set (on open = Date(); if I leave it empty, I get a Type Mismatch [null?] error when I call frmCalendar). Yet, when frmCalendar closes the date displayed correctly in by text box.
I put the date manipulation code in the txtStart After Update event -- Nothing happens even though the date is updated.
I then tried putting a txtStart.SetFocus at the end of the code which calls frmCalendar and the date manipulation code in the On Got Focus event, guess what? The Set Focus closes my calling form. I'm stumped! Here is the code calling frmCalendar:
Dim frmCal As Form
Dim ctlD As Control
Dim datToday As Date
Set ctlD = Me!txtStart
DoCmd.OpenForm "frmCalendar", , , , , acHidden
Set frmCal = Forms("frmCalendar"
With frmCal
Set .DateControl = ctlD
.InitialDate = ctlD.Value
.Visible = True
End With
Here is the code from frmCalendar:
Option Compare Database
Option Explicit
Private mctlDate As Control
Public Property Set DateControl(ByVal ctlDate As Control)
Set mctlDate = ctlDate
End Property
Public Property Let InitialDate(datD As Date)
Me!ctlCalendar = datD
End Property
Private Sub SetAndClose()
If mctlDate Is Nothing Then
MsgBox "The Date has not been set", , "Calendar Form Error"
Else
mctlDate = ctlCalendar.Value
End If
DoCmd.Close
End Sub
Private Sub ctlCalendar_Click()
SetAndClose
End Sub
Private Sub ctlCalendar_KeyUp(KeyCode As Integer, ByVal Shift As Integer)
Select Case KeyCode
Case vbKeyReturn
SetAndClose
Case vbKeyEscape
DoCmd.Close
End Select
End Sub
Private Sub ctlCalendar_updated(code As Integer)
End Sub
How can I call the calendar and then execute my date commands?
Any help will be appreciated.
Thanks.
Larry De Laruelle
larry1de@yahoo.com