View Full Version : access Cal Control


SPARKEE
04-25-2008, 07:12 AM
I am trying to set up a form that uses Microsoft Calender Control to select dates. I have managed to get it working, but it always goes back to today's date when I go to next form page. I need to it stay on selected date until I change it.


This is the code I am using;

Option Compare Database
Option Explicit
Dim cboOriginator As ComboBox

Private Sub BusinessDay_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboOriginator = BusinessDay
' Unhide the calendar and give it the focus
ocxCalendar.Visible = True
ocxCalendar.SetFocus
' Match calendar date to existing date if present or today's date
If Not IsNull(cboOriginator) Then
ocxCalendar.Value = cboOriginator.Value
Else
ocxCalendar.Value = Date
End If
End Sub

Private Sub ocxCalendar_Click()
' Copy chosen date from calendar to originating combo box
BusinessDay.Value = ocxCalendar.Value
' Return the focus to the combo box and hide the calendar
BusinessDay.SetFocus
ocxCalendar.Visible = False
Set cboOriginator = Nothing
End Sub