I have the code below in the mousedown field of a combo box control. The first field works great, the calendar pops up and when you select a date it populates the start date. However, when you click in the end date box, the start date box populates also. Does anyone know what I'm doing wrong? Any help would be appreciated. Thanks!
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)
' 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)
' 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
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)
' 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)
' 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