ActiveX calendar - how set default Date

GetReel

Registered User.
Local time
Today, 09:51
Joined
May 22, 2003
Messages
67
Im using the Active X MSCAL.Calendar.7 to set Start and End date fields on a form. My problem is I cant get the calender to default todays date. When the calendar opens, the date is set to march 2002.

Any solutions anyone.?
 
This should do it:

Me![NameOfCalendarControl].Value = Date

hth,
Jack
 
Thanks jack.

where exactly should I put it.

Private Sub Calendar_Click()

'copy the selected date across to the start date field,
'hide the calendar and move to the end button
If Me.cmdDate.Caption = "Set Start Date" Then
Me.StartDate.Value = Me.Calendar.Value
Me.cmdDate.Caption = "Set End Date"
Me.cmdDate.SetFocus
Me.Calendar.Visible = False
Else
If Me.cmdDate.Caption = "Set End Date" Then
Me.EndDate.Value = Me.Calendar.Value
Me.cmdDate.Caption = "Reset Dates"
Me.cmdDate.SetFocus
Me.Calendar.Visible = False

End If
End If
End Sub
 
Put the code in the On Load event of the form that has the calendar on it. Sorry I didn't put that in the first time...

Jack
 
I actually tried placing it in Onload Event but it didnt work. I thought that it should go else where and thats why I replied asking where does it go. I cant understand what the heck im doing wrong. The name of the Calendar control is simply Calendar.
Me![Calendar].Value = Date.

It has me stumped.
 
I has me stumped too! Try making a new form and adding the Calendar control to it and put the code in the On Load event and see if that works when you open the form. And be sure that the Name property under the Other tab on the property sheet for the control says Calendar...

hth,
Jack
 
Thanks Rich! It's always the simple things that drive us crazy! I was trying to edit the properties on the calendar for about a half hour. Wish I had checked here first and saved myself the headache. Worked like a champ!
 
You need to realize that with the calendar's default set to today's date in the OnLoad event, it will only remain the default as long as you don't select another date from the calendar. If, for instance, you click on tomorrow's date on the calendar, then this is the date that will show on the calendar when you go to another record. To have today's date always be the default when going to a new record, you need to set it elsewhere, such as the OnCurrent event.
 
I'm having a similar issue. I'm brand new to access and sql code so I'm completely lost when attempting to edit the code directly.
I have a form in which I'm attempting to execute a "new page" and "set calendar to today".

I tried to use rich's code but it attempted to debug.

Here's what I have as of now.

Private Sub Command19_Click()
End Sub
Private Sub AddRecord_Click()
On Error GoTo Err_AddRecord_Click

DoCmd.GoToRecord , , acNewRec
Exit_AddRecord_Click:
Exit Sub
Err_AddRecord_Click:
MsgBox Err.Description
Resume Exit_AddRecord_Click

End Sub

Private Sub Calendar7_Updated(Code As Integer)
Me![NameOfCalendarControl].Value = Date
End Sub
 
Last edited:
Delete this:
Code:
Private Sub Calendar7_Updated(Code As Integer)
Me![NameOfCalendarControl].Value = Date
End Sub
You'd be setting the calendar's value after you'd already selected a date. Also, you forgot to replace NameOfCalendarControl with the actual name of your calendar. Instead, use this
Code:
Private Sub Form_Current()
 Me.Calendar7.Value = Date
End Sub

When you move to a new record the calendar's default date will be the current date.
 
Thanks Missingling. That did work out very well. However now whenever I press "any" of my event buttons that I've created such as "view last casualty" or "view first casualty" it always sets the date on the calendar to the current date.

Where as before it did save whatever date I clicked. Most likely I've deleted something important and once again my apologizes for my coding errors.
 

Users who are viewing this thread

Back
Top Bottom