Calendar Control

  • Thread starter Thread starter Antonio
  • Start date Start date
A

Antonio

have a form containing a combo box and several
different data fields. I use the combo box to find a
value on my form. Specifically a date(mm,dd,yy)and its
associated data. I want to add a calendar control to the
form that displays when the mouse is placed over the
Combo Box and clicked. I found instructions at

http://support.microsoft.com/default.aspx?scid=kb;en-
us;190194&Product=acc

and it seems to work great. The calendar pops up when you
click in the combo box, the calendar fills in the date
that the user chooses on in the calendar...but, after the
date is displayed in the combo box, nothing happens. As
of now (with no calendar and just the combo box), you can
manually enter in a date and hit enter. This will cause
the form to display the date and associated data you
asked for. Also, you can click on the drop down arrow on
the combo box and manually locate the date you are
looking for, and again the date and associated data
displays on the form. But after I add the Calendar
Control, the combo box no longer locates the date and
associated data. Instead, it attempts to change the date
of the first record to the date specified on the calendar
control. I dont understand what I am doing wrong.
Thanks in advance.
Antonio
..
 
Antonio,

In a Human Resources application we have a multi-use form
for specifying date selection. This multi-use form is
opened as a pop-up modal from VBA in the form doing the
opening, i.e. the one with a control whose source is a
date/time field in a table. The following is from such an
opening form looking for a vacation date:

Private Sub VacationDate_DblClick(Cancel As Integer)
Dim strControlName As String
strControlName = "[Forms]![FM10]![FM14]![VacationDate]"
DoCmd.OpenForm "FMDateSEL", , , , , , strControlName
' opened as modal popup, so will be closed before exiting
' this sub . . .
' Open event for popup sets captions and Close event sets
' date (VacationDate)
End Sub

In this code snippet, FM10 is the main employee
maintenance form, FM14 is a subform which captures
vacation data, and [VacationDate] is the control tied to a
table. As you can see, we chose to let the calendar
control be optional, only invoked if the user double
clicks on the [VacationDate] control. This allows the
user to simply key a date if doing so is preferable.
FMDateSel is the multi-use form with the calendar control.

The following is the code from the multi-use form's Open
event:

Private Sub Form_Open(Cancel As Integer)
Dim strControlName As String
strControlName = [Forms]![FMDateSEL].OpenArgs
Select Case strControlName
' in order of appearance on tabs of FM10 Employee
' Maintenance form
<. . . several Case statements, then this one . . .>
Case "[Forms]![FM10]![FM14]![VacationDate]"
[Forms]![FMDateSEL].Caption = " Select Vacation Date "
[Forms]![FMDateSEL]![DateSelectionTitle].Caption = _
[Forms]![FMDateSEL].Caption
<. . . several more Case statements . . .>
End Sub

This Open event code sets user friendly titles (captions)
on the multi-use form. The OpenArgs attribute here is the
key for making our FMDateSel a multi-use form.

The user then interacts with the calendar control
(MSCAL.ocx) selecting a date. And nothing happens, just
as you said! But we put a small-font instruction line at
the bottom of the form instructing the user to select
their date AND then close the window (using the "X" on the
form).

So in the Close event for the form we have the following
VBA:

Private Sub Form_Close()
Dim strControlName As String
If Not [Forms]![FMDateSEL]![DateSelect].ValueIsNull Then
Select Case [Forms]![FMDateSEL].OpenArgs
' in order of appearance on tabs of FM10 Employee
' Maintenance form
Case "[Forms]![FM10]![FM14]![VacationDate]"
[Forms]![FM10]![FM14]![VacationDate].Value = _
[Forms]![FMDateSEL]![DateSelect].Value
End Select
End If
End Sub


Hate using all that hard coding of form control names,
etc., but this approach has been up and running with zero
problems for about 2 years now. We are A2000 in W2000
environment.

Best 2 U,

The Maul Man
 
Back
Top