Link to home
Start Free TrialLog in
Avatar of ml-sd
ml-sdFlag for United States of America

asked on

Choosing a Day in the ActiveX Calendar

When you choose a month and year on the active x calendar in access, is there a way, using VBA to default it to a day automatically ?
Avatar of rockiroads
rockiroads
Flag of United States of America image

if you are going to set the day, why don't you just set the date so you cover all 3 elements of a date.
eg

cal.Value = CDate("10/11/2011")

or use dateserial (yyyy,mm,dd)

cal.value = dateserial(2011,11,10)
yeah, I played around with this for a while and there was no easy way (at least that I could find) to do this via an Event...
Avatar of ml-sd

ASKER

The input from the the active X calendar opens up a monthly calendar form.....   therefore the actual day isn't important  and users forget the keystroke....  i was trying to just make the day any day without input.
so why not default to todays date then?

cal.value = now()
Avatar of ml-sd

ASKER

I have the form load event todays date.  then the user can choose a different month to look at.
so any particular day, on the NewMonth event, set it to the 1st?

eg control called cal

Private Sub cal_NewMonth()
    cal.Value = DateSerial(Year(cal.Value), Month(cal.Value), 1)
End Sub

you also have a NewYear event
Avatar of ml-sd

ASKER

Im using some code simillar to this...  i put in the lost focus event .However, unless a day is pressed  it dosent work.  I then created a subroutine  using your code and received this error : Runtime error 424 object required
can you post what you have done so far? you did change "cal" to the name of your control right?
Avatar of ml-sd

ASKER

Im sorry for the delay in posting, I got tied up on another job...  Thanks so much for your patience.
Here is what I have...   i was going to use the lost focus event on the calendar on the datepickerF,  but i couldnt get it to work
Calendar.mdb
Your control is called Calendar

If the attached code is added to your form, then the first day of the month is selected each time you change the month or year
Private Sub Calendar_NewMonth()
     Calendar.Value = DateSerial(Year(Calendar.Value), Month(Calendar.Value), 1)
End Sub

Private Sub Calendar_NewYear()
     Calendar.Value = DateSerial(Year(Calendar.Value), Month(Calendar.Value), 1)
End Sub

Open in new window

Avatar of ml-sd

ASKER

Well, it almost works....   I does default a date.   But you cant change the month and year at the same time.  also when I go back to the form to choose another month  It will not allow me to make another choice ??
Ok, gave it some test as realised when selecting a new month it does not update the calendar value! Let me look into this a little more
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ml-sd

ASKER

as it turns out, in access 2003, I have found no way to auto choose a date with the active x calendar. I am told in 2007 and 2010 you can. The suggestion using some combo boxes and create my own choices worked.  
thanks for all your input