Visual Basic for Popup Calendar

home

Instructions

  • Convert your date text box on your form to a combo box
  • Apply the following visual basic to the "on mouse down" event of the box (in this same, the assumption is that the name of the calendar is calendar6, and the date field being applied to is "samples_sent")
    Private Sub Samples_Sent_MouseDown(Button As Integer, _ Shift As Integer, X As Single, _ Y As Single)
    ' Show Calendar6 and set its date.
    Calendar6.Visible = True
    Calendar6.SetFocus
    ' Set to today if Samples_Sent has no value.
    Calendar6.Value = IIf(IsNull(Samples_Sent), Date, Samples_Sent.Value)
    End Sub
  • Insert an Active X onto your form, a calendar control
  • Right click on the calendar, under PROPERTIES set visible to NO and name it calendar1, calendar2, whatever you wish.
  • Apply the following visual basic to the "On Click" event of the calendar (in this same, the assumption is that the name of the calendar is calendar6, and the date field being applied to is "samples_sent")
    Private Sub Calendar6_Click()
    ' Set Samples_Sent to the selected date and hide the Calendar6.
    Samples_Sent.Value = Calendar6.Value
    Samples_Sent.SetFocus
    Calendar6.Visible = False
    End Sub