PDA

View Full Version : Solved: Call the same calendar control with different combo box



Victor
03-24-2009, 08:45 AM
Hi all:

According to Mr. Martin Green's site and quote "Each date field combo box ( CboStartDate and CboStartDate2) can call the same calendar control, but the calendar needs to know which combo called it so that it can return a date to the correct one", thats why I have 2 CboSartDate, and CboStartDate2 combo box name.

Both combo box called the same calendar control (ocxcalendar) even They have different names.

Any idea what I am doing wrong?

Thanks for the help.

Victor




Option Compare Database
Option Explicit
Dim CboOriginator As ComboBox

Private Sub CboStartDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ocxcalendar.Visible = True
ocxcalendar.SetFocus
If Not IsNull(CboStartDate) Then
ocxcalendar.Value = CboStartDate.Value
Else
ocxcalendar.Value = Date
End If
End Sub

Private Sub CboStandartDate2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ocxcalendar.Visible = True
ocxcalendar.SetFocus
If Not IsNull(CboStartDate) Then
ocxcalendar.Value = CboStartDate.Value
Else
ocxcalendar.Value = Date
End If
End Sub
Private Sub ocxcalendar_Click()
Set CboOriginator = CboStartDate
CboStartDate.Value = ocxcalendar.Value
CboStartDate.SetFocus
ocxcalendar.Visible = False
Set CboOriginator = Nothing
End Sub

hansup
03-24-2009, 01:29 PM
According to Mr. Martin Green's site and quote "Each date field combo box ( CboStartDate and CboStartDate2) can call the same calendar control, but the calendar needs to know which combo called it so that it can return a date to the correct one", thats why I have 2 CboSartDate, and CboStartDate2 combo box name.

Both combo box called the same calendar control (ocxcalendar) even They have different names.Try this version:

Option Compare Database
Option Explicit
Dim cboOriginator As ComboBox

Private Sub cboStartDate_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Set cboOriginator = cboStartDate
ocxCalendar.Visible = True
ocxCalendar.SetFocus
If Not IsNull(cboStartDate) Then
ocxCalendar.Value = cboStartDate.Value
Else
ocxCalendar.Value = Date
End If
End Sub

Private Sub cboStartDate2_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
'Private Sub cboStandartDate2_MouseDown(Button As Integer, _
' Shift As Integer, X As Single, Y As Single)
Set cboOriginator = cboStartDate2
ocxCalendar.Visible = True
ocxCalendar.SetFocus
If Not IsNull(cboStartDate) Then
ocxCalendar.Value = cboStartDate.Value
Else
ocxCalendar.Value = Date
End If
End Sub

Private Sub ocxcalendar_Click()
'Set cboOriginator = cboStartDate
'cboStartDate.Value = ocxCalendar.Value
'cboStartDate.SetFocus
cboOriginator.Value = ocxCalendar.Value
cboOriginator.SetFocus
ocxCalendar.Visible = False
Set cboOriginator = Nothing
End Sub
Good luck,
Hans

Victor
03-26-2009, 04:56 PM
Thanks for the help. Victor

Solution from sample code from Mr. Martin Green's site


Option Compare Database
Option Explicit
Dim cboOriginator As ComboBox
Private Sub cboStartDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' 1 Note which combo box called the calendar
Set cboOriginator = cboStartDate
' 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 cboEndDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' 2 Note which combo box called the calendar
Set cboOriginator = cboEndDate
' 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
cboOriginator.Value = ocxCalendar.Value
' Return the focus to the combo box and hide the calendar and
cboOriginator.SetFocus
ocxCalendar.Visible = False
' Empty the variable
Set cboOriginator = Nothing
End Sub
Private Sub ocxCalendar_Updated(Code As Integer)
End Sub