Today's date in Pop-up calanedar

L

Linda

Hi,

I have a few pop up calendars and I would like it to default to todays date.

Here is my code:
Private Sub duedate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
cal.Visible = True
cal.SetFocus
If Not IsNull(duedate) Then
cal.Value = duedate.Value
Else
cal.Value = DATE
End If
End Sub

Private Sub cal_Click()

duedate.Value = cal.Value
duedate.SetFocus
cal.Visible = False
End Sub

It seems as though it is defaulting to the date I created the calendar on
the form. I have ValueIsNull property set to yes.
Right now the calendar comes up with the month of March.

Am I missing something?

Thanks
Linda
 
L

Linda

What does the Me represent agian?

I tired the statement without the Me of course in the On Load event and it
didn't work.
 
C

CJ

The form that you are currently on is Me. Your explanation suggests that the
form that contains the Calendar control is Me. Therefore, it is trying to
locate the calendar somewhere on itself. If the calendar is on a subform
then you would have to specify the location of the subform on Me.

For example: Me.SubForm1.Form!Calendar.Value = Date Would locate the
calendar if it were on SubForm1 which is on the Main form, Me.
 
C

CJ

OK, so everything is on the Main form (Me). You need to use Me throughout
your code so that Access
knows to find the values that it requires from the form controls.

So, on the Form_Load event of your main form, enter

Me.Cal.Value = Date
(This will set the default date of the calendar even though it is not
visible)

The rest of your code is very similar to what I use. I have added Me.
wherever it is necessary.
You should be able to copy and paste this into your code.

Private Sub duedate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Me.cal.Visible = True
Me.cal.SetFocus
If Not IsNull(Me.duedate) Then
Me.cal.Value = Me.duedate
Else
Me.cal.Value = DATE
End If
End Sub

Private Sub cal_Click()
Me.duedate = Me.cal.Value
Me.duedate.SetFocus
Me.cal.Visible = False
End Sub

After you make your changes, remember to go to the Visual Basic Debug menu
and choose Compile. This is the first
step in allowing Access to make sure that everything is written correctly.
You will also notice that
after typing Me in front of things, the control names will capitalize. This
means that Access can find them.

CJ
 
L

Linda

Since I have multiple calendars, I changed the main one for now to include Me
in the code. When I did this, it did not capitalize my control names and
when I ran complile there were no errors. When I go to run the form, it
still defaults to March.
Am I doing something wrong?
 
C

CJ

Hi Linda:

What is the name of your calendar object? The default name that access gives
a calendar is CalCtl1. When you open the calendars properties, what does it
say in the Name field of the Other tab? Wherever I have Cal in the code
below, be sure to put in the name of the calendar from the properties Name
field.

Also, did you remember the code for the Form_Load event? Me.Cal.Value = Date

Also, you did not mention, is your calendar working? Does it show up,
disappear and fill in the date as expected?
 
L

Linda

Hi,

I actually got it to work. I used the Today method and that seems to have
fixed it for me.
Thanks for all your help!

Thanks
Linda
 

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

Top