Calendar Control

G

Guest

I want to use a calendar control to allow the user to select a start date and
end date for a range on a report, I have a text box that is named Start_Date
and another named End_Date, I have added a calendar control for each text box
Calendar8 and Calendar9. Each calendar is invisible until a user clicks a
button to bring them up.

My question is how do I get the textboxes to display the date that the user
selects from the calendar control? I tried this:

Private Sub Calendar8_Updated(Code As Integer)
Me.Start_Date.Value = Me.Calendar8.Value

Me.Calendar8.Visible = False

End Sub

But is does nothing. Any help is appreciated more than you know!
 
G

Guest

Rather than using the calendar control's Updated event procedure try using
its Click event procedure. Although not exposed in the control's properties
sheet it does exist and can be called in the form's module.

I use a separate form to hold the calendar control. The form can be called
from the DblClick event procedure of any control on a form with:

Dim strControl As String

strControl = Me.ActiveControl.Name

' attempt to open calendar form
If Not OpenCalendar(Me.Name, strControl) Then
MsgBox "Unable to open calendar", vbExclamation, "Error"
End If

This calls the following function in a standard module:

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

On Error GoTo ErrHandler

OpenCalendar = True

' open calendar form in dialog mode, passing names of form
' and control to it as OpenArgs property
DoCmd.OpenForm "frmCalendar", WindowMode:=acDialog, _
OpenArgs:=strCurrentForm & "/" & strCurrentControl

ExitHere:
Exit Function

ErrHandler:
OpenCalendar = False
Resume ExitHere

End Function

The module of the form holding the calendar control is:

Option Compare Database
Option Explicit

Private Sub Form_Close()

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

' parse form's OpenArgs property to get calling
' form and control's names and set control's value
' to date selected in calendar 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

End Sub


Private Sub ocxcalendar_Click()

DoCmd.Close

End Sub

Private Sub ocxcalendar_GotFocus()

' set calendar control to current date
Me.ocxcalendar.Today

End Sub

Ken Sheridan
Stafford, England
 
G

Guest

Rather than using the calendar control's Updated event procedure try using
its Click event procedure. Although not exposed in the control's properties
sheet it does exist and can be called in the form's module.

I use a separate form to hold the calendar control. The form can be called
from the DblClick event procedure of any control on a form with:

Dim strControl As String

strControl = Me.ActiveControl.Name

' attempt to open calendar form
If Not OpenCalendar(Me.Name, strControl) Then
MsgBox "Unable to open calendar", vbExclamation, "Error"
End If

This calls the following function in a standard module:

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

On Error GoTo ErrHandler

OpenCalendar = True

' open calendar form in dialog mode, passing names of form
' and control to it as OpenArgs property
DoCmd.OpenForm "frmCalendar", WindowMode:=acDialog, _
OpenArgs:=strCurrentForm & "/" & strCurrentControl

ExitHere:
Exit Function

ErrHandler:
OpenCalendar = False
Resume ExitHere

End Function

The module of the form holding the calendar control is:

Option Compare Database
Option Explicit

Private Sub Form_Close()

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

' parse form's OpenArgs property to get calling
' form and control's names and set control's value
' to date selected in calendar 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

End Sub


Private Sub ocxcalendar_Click()

DoCmd.Close

End Sub

Private Sub ocxcalendar_GotFocus()

' set calendar control to current date
Me.ocxcalendar.Today

End Sub

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

Similar Threads


Top