Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveX Calendar in Acc97 2

Status
Not open for further replies.

wynoski

Technical User
Aug 22, 2002
5
0
0
US
Hello. I have a simple question regarding the use of ActiveX Calendar (MSCAL.Calendar.7) in Acc97. I have the calendar set up so that users can click on a date from the calendar (instead of manually entering a date). As of now, I have no idea how to assign the date they highlight to a field in my form as soon as they select a date. There is no OnClick event for the calendar. The only way I've managed to do this is by creating a button for users to click after they have selected the date they want from the calendar. While this is still easier (and less error prone thatn having user manually enter date), I'd like for them to be able to click the calendar once rather than click the calendar and then click the button.

Anyone have any ideas? I've tried just about everything (form OnCurrent, calendar OnUpdate, etc).

Many thanks!
 
I have used the calendar control in a number of my apps.
So far, I have always used it in conjunction with a command button. I declare a variable(s) for the date, then set their values by what the user has selected on the calendar controls:

Dim StartDate As Date
Dim EndDate As Date

StartDate = Forms![DateForm]![ActiveXCtl1].Value
EndDate = Forms![DateForm]![ActiveXCtl2].Value

I imagine you could set the value of an object based on the calendar control's value using the On Lost Focus event.
 
First
Create a blank form called Calendar
On the on open event input the following Code

-------------------------------------------------------------------------
Option Compare Database
Option Explicit

Public mctlDate As Control


Public Property Set DateControl(ByVal ctlDate As Control)

Set mctlDate = ctlDate

End Property

Public Property Let InitialDate(datD As Date)

Me!ctlCalendar.Value = datD

End Property

Public Sub SetAndClose()

If mctlDate Is Nothing Then
MsgBox "The DateControl property has not been set", , _
"Calendar Form Error"
Else
mctlDate = ctlCalendar.Value
End If
'TODO:
DoCmd.Close acForm, Me.Name, acSaveYes

End Sub

Public Sub ctlCalendar_Click()

SetAndClose

End Sub


Public Sub ctlCalendar_KeyUp(KeyCode As Integer, ByVal Shift As Integer)

Select Case KeyCode
Case vbKeyReturn ' carriage return
SetAndClose
Case vbKeyEscape ' escape
DoCmd.Close
End Select
DoCmd.Maximize
End Sub



Public Sub Form_Open(Cancel As Integer)
DoCmd.Restore
End Sub
==========================================================================================================================
SECOND
Create a Button named CmdCalendar on your current form
OnClick event paste this code

I called the field name (Date_From)

Private Sub CmdCalendar_Click()

Dim frmCal As Form
Dim ctlD As Control
Dim db As Database
Set db = CurrentDb()
Dim rst As Recordset
Dim recClone As Recordset
Dim intNew As Integer
Dim i As Integer, z As Integer

Me!Date_From = Now()
Set ctlD = Me!Date_From
DoCmd.OpenForm "Calendar", , , , , acHidden
Set frmCal = Forms("Calendar")
With frmCal
Set .DateControl = ctlD
.InitialDate = ctlD.Value
.Visible = True
End With

'Time_From.SetFocus

RefreshDatabaseWindow


End Sub
Hope this helps
Hymn
 
Nevets and hymn,

Thank you both for your almost instantaneous reply to my question. Both your answers were very useful. It was my first time using the ActiveX calendar.

hymn - your code works like a charm! I placed the code you assigned to the cmdCalendar button in the form's OnOpen event. This way, the format is set from the get-go. All the user has to do is select the date from the calendar and the field is updated with the new date.

MANY MANY MANY thanks to you both!
 
I want to use the control in conjunction with reports. The user should be to select a name from a combo box, then select a report. As soon as the user clicks on the button (that has the report name) I want the calendar control to pop so that he or she can select a date and click ok. Two parameters will be sent to the report the name of the person selected from the combo box and the date ranges selected from the calendar control. Any help with that will be greatly apprecaited.
Thank you in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top