Calendar Control on a form

D

DScheingold

I have a form with a date field in it with a macro that calls a form with a
calendar control when clicked on. My problem is getting the date form the
calendar control to populate the date field on the form so I can then update
the file. has anyone been able to do this?
 
B

Bob Barnes

This code will work w/ a series of small Buttons w/ a "C" on them for
Calendar...
Change the Booleans to "True" for the particular textbox.

This "C" Button is next to a textbox "ASwipe" formatted for mm/dd/yy.

Private Sub cmdASwipe_Click()
On Error GoTo AAA1
bAC = False: bBC = False: bDepDate = False: bBegTrend = False: bEndTrend =
False
bCredCard = False: AX930.Visible = True: bASwipe = True: bBSwipe = False
If Not IsNull(ASwipe) Then
Me.AX930.Value = ASwipe
Else
Me.AX930.Value = Date
End If
AAA2:
Exit Sub
AAA1:
MsgBox Err.Description
Resume AAA2
End Sub

Private Sub AX930_Click()
If bAC = True Then
BegDaily = AX930.Value: BegDaily.SetFocus: AX930.Visible = False
If Not IsNull(BegDaily) Then cmdDailySum.Enabled = True: cmdKimEM.Enabled =
True
ElseIf bBC = True Then
EndDaily = AX930.Value: EndDaily.SetFocus: AX930.Visible = False
ElseIf bDepDate = True Then
DepDate = AX930.Value: DepDate.SetFocus: AX930.Visible = False
ElseIf bBegTrend = True Then
BegTrend = AX930.Value: BegTrend.SetFocus: AX930.Visible = False
ElseIf bEndTrend = True Then
EndTrend = AX930.Value: EndTrend.SetFocus: AX930.Visible = False
ElseIf bCredCard = True Then
CCDate = AX930.Value: CCDate.SetFocus: AX930.Visible = False
ElseIf bASwipe = True Then
ASwipe = AX930.Value: ASwipe.SetFocus: AX930.Visible = False
If Not IsNull(ASwipe) Then cmdSwipe.Enabled = True
ElseIf bBSwipe = True Then
BSwipe = AX930.Value: BSwipe.SetFocus: AX930.Visible = False
Else
AX930.Visible = False
End If
End Sub

HTH - Bob
 
K

Ken Sheridan

Here's my method using a form frmCalendar with a calendar control ocxCalendar:

1. Add the following function to a standard module:

Public Function OpenCalendar(strCurrentForm As String, _
strCurrentControl As String) As Boolean

On Error GoTo ErrHandler

OpenCalendar = True

DoCmd.OpenForm "frmCalendar", WindowMode:=acDialog, _
OpenArgs:=strCurrentForm & "/" & strCurrentControl

ExitHere:
Exit Function

ErrHandler:
OpenCalendar = False
Resume ExitHere

End Function

2. In the calendar form's Close event procedure out:

Dim intSlashPos As Integer
Dim strForm As String, strControl As String

' parse the form's OpenArgs property
' to get names of calling form and control
If Len(Me.OpenArgs) > 0 Then
intSlashPos = InStr(1, Me.OpenArgs, "/")
strForm = Left$(Me.OpenArgs, intSlashPos - 1)
strControl = Mid$(Me.OpenArgs, intSlashPos + 1)
Forms(strForm).Controls(strControl) = ocxCalendar
End If

3. In the calendar control's Click event procedure put:

DoCmd.Close acForrm, Me.Name

NB: the Click event procedure is not shown in the control's properties
sheet, but is available in the VBA window with the form's module open by
selecting the calendar control from the top left combo box and its Click
event procedure from the top right combo box.

4. To open the calendar form put the following code in a suitable event
procedure in any form with a control into which you want to insert the date;
I generally use the date control's DblClick event procedure:

If Not OpenCalendar(Me.Name, "YourDateControl") Then
MsgBox "Unable to open calendar", vbExclamation, "Error"
End If

where " YourDateControl" is the name of the date control

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top