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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active X Calendar control 1

Status
Not open for further replies.

Brambojr

Technical User
Oct 26, 2000
73
0
0
US
I have added an Active X control on a few of my forms to help speed the entry on date fields. Problem: It forever opens to the day I created it. Nov 2000. I want it to default to Date() but nothing seesm to be working. I can work decently with Access but am a VB moron. Can anyone help me out? I'm fairly sure it's an easy fix.

Thanks
 
Create an ActiveX calendar called calend, and put this code on the control you want t0 populate from the calendar. As an example try this (you'll have to adapt it to your situation):

Private Sub Date_measured_Click()
'set the calendars dates to today
Forms![Patients]![calend].Today
Forms![Patients]![calend].Refresh
Forms![Patients]![calend].Visible = True
End Sub

Private Sub Date_measured_Exit(Cancel As Integer)
Forms![Patients]![calend].Visible = False
End Sub

Although this works on the PC I made the application on, when other users installed the application it exhibited the problem you described. So this may not solve your problem completely.
 
I ran into a similar problem when working with the Calendar Active X control in developing an application with lots of dates. It took me quite awhile to resolve so am happy to pass along my fix.

My fix involves code on the form which accesses the calendar and on the calendar form itself. However, this may be a bit more than you wanted. Best of luck.


First declare variable in Global, if control is used on more than one form.

Public ctl As Control

The following code is on the form opening the calendar. I made the date field to be updated a command button by using the following code as a "double-click" event.

***Code Start

Private Sub CCStart_Date_DblClick(Cancel As Integer)
'Open calendar form to select date

'First refresh date, in case it was revised
Me.Refresh
'Second, set up variable for active datefield in specified form for calendar lookup/revision
Set ctl = Forms![frmChargeCodes Detail Subform]![CCStart Date]
'The preceding line of code sets up a variable for the control field to be updated.
'Then, Open Calendar
Dim stDocName As String
stDocName = "frmCalendar" 'name of form containing Active X calendar
DoCmd.OpenForm stDocName
End Sub
****End Code

The following code controls what date is presenting on the calendar when it is brought up. The "on load" event On calendar form (which contains the Active X calendar named "GetDate") determines if the control field on original form is blank and if so, brings up today's date. If not blank, it brings up date of control.

***Code start

Private Sub Form_Load()

'Once calendar form is opened, sets calendar to today's date if date field is empty
If IsNull(ctl) Then
Me!GetDate = Date
Else
'If active datefield is not empty, brings up active date on calendar
Me!GetDate.Value = ctl
End If
End Sub

***Code end

The following code selects date from calendar and populates the control on the form with the new date.

***Code start

Private Sub GetDate_DblClick()
'On DblClick, the active datefield on specified form is changed to calendar date
ctl = Me!GetDate.Value
End Sub
***Code end
 
All i did to get the calendar to show the current date was to type the following in the form load event:


Private Sub Form_Load()
Calendar.Today
End Sub ruth.jonkman@wcom.com
 
[Calendar Control Name].Today

USED to work for me (in Access 97). Now, in Access 2000, it doesn't!

I can't say for sure what version of the control I had in Access 97 but in Access 2000 it's Calendar Control 9.0

Access 2000 Help files are horribly foreshortened! What happened to all the detailed Help info that Access 97 had????

".Today" seems to be an undocumented (at least anywhere I know to look) Method.

Has anyone gotten the 9.0 calendar control to open with today's date? Please help.
 
DK77

The calendar control 9.0 does seem different in access 2000.
i solved the problem by using the now() function with the Got_Focus and Form_Open Events. here is the code (i named my activeX control ActiveXCtlCalendar):

Private Sub Form_Open(Cancel As Integer)

Me.ActiveXCtlCalendar.SetFocus

End Sub


Private Sub ActiveXCtlCalendar_GotFocus()

Me.ActiveXCtlCalendar = Format(Now(), "Short Date")
Me.Refresh

End Sub
 
DK77

Sorry, i gave you the wrong code. try this on the from_open event:

Private Sub Form_Open(Cancel As Integer)

Me.ActiveXCtlCalendar.SetFocus
Me.ActiveXCtlCalendar = Format(Now(), "Short Date")
Me.Refresh


End Sub
 
ruthcali (Programmer) writes

Private Sub Form_Load()
Calendar.Today
End Sub

Thank-you. I've been hunting for a solution for ages and this is the only one that worked!! I am using Access 2002 but saving in 2000 format.

Cheers!
 
I hope this will help. I had a similar issue which was driving me nuts. I wanted the calendar to default to either (a) today's date if the date field of my table was null (empty), or (b) the value of the date field. It wasn't working but I realised I'd set the "allow edits" property of my form to false. So I did the following

form.allowedits = True
If IsNull(fldDate.value) = True then
calControl.value = Date ( no brackets and not Today)
Else
calControl.value = fldDate.value
End If
Form.Allowedits = False

I used similar code on my custom record navigation button so that the calendar would change to reflect either the current record's date field or today's date. It works fine now. I'm using Access 2000.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top