Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Aug 2001
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Set Calender Contol to Current Month/Day/Year (Access 97 SR-2)

    Is there a way to program the Calender Control to display the current date when opening? The name of my calender control is 'SelectDate' and I have tried the following code in the open event for the form...it does not seem to work:

    me.SelectDate.value = Date

    I know that this should work, but I am having no success. Any ideas would be greatly appreciated.

    Thank,
    Sean

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Set Calender Contol to Current Month/Day/Year (Access 97 SR-2)

    Is SelectDate the *name* of the calendar control on your from? I usually dim a Calendar object at the top of the form module like this:

    Private WithEvents mOleCal As Calendar

    Then I use that to refer to the calendar control in my code. This works for me:

    mOleCal.Value = Date
    mOleCal.Refresh
    Charlotte

  3. #3
    New Lounger
    Join Date
    Aug 2001
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set Calender Contol to Current Month/Day/Year (Access 97 SR-2)

    Thanks so much for the response. I finally did get it working by putting the code me.Calender.Value = Date in the GotFocus event of the calendar control. This seemed to work. However, I also gave your idea a try and am running into some problems.

    In the Gen Dec section, I declared the variable:

    Private WithEvents mOleCal As Calendar

    Then in the OPEN event of the form I place the following code:

    mOleCal.Value = Date
    mOleCal.Refresh

    I then changed the name of the Calendar control from 'Calendar' to 'mOlecal'. Maybe this was not the correct step. At anyrate, when I open the form, I get error 91: Object Variable or With Block Variable Not set.

    Any ideas?

    Thanks so much,
    Seam

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Set Calender Contol to Current Month/Day/Year (Access 97 SR-2)

    Sorry, but you misunderstood. The object variable is declared as a Calendar object. The you set the object variable equal to the calendar control on the form. Don't give them the same name, because that will just totally confuse Access.

    In the open event do something llike this:

    Set mOleCal = Me!Calendar1
    mOleCal.Value = Date
    mOleCal.Refresh

    Where Calendar1 is the actual name of the calendar control. You don't have to use the object variable, you can refer directly to the control, but then take out the declaration because you don't need it. I use the object variable reference for other purposes, which is why it was in the code I copied.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •