Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2006
    Posts
    7

    Unanswered: Open ActiveX control through a command button

    I have a form that requests date input from users. To make it idiot-proof I want to use the calendar (MSCAL.OCX). I can insert the calendar without a problem, however, I want to show (activate) the calendar through a command button (conservation of space). I am having trouble activating the calendar through the command button.

    First, I tried the following code in the form's field:

    Private Sub ScheduledDestructDate_GotFocus()
    Dim OCXObject As Object
    Set OCXObject = GetObject("C:\Program Files\Microsoft Office\Office11\MSCAL.OCX")
    End Sub

    and I get the following error message:

    "File name or class name not found during automation operation"

    When I try to set it up through the command button, using this code:

    Private Sub CmdCalendar1_Click()
    On Error GoTo Err_CmdCalendar1_Click
    Dim stAppName As String
    stAppName = "C:\Program Files\Microsoft Office\OFFICE11\MSCAL.OCX"
    Call Shell(stAppName, 1)
    Exit_CmdCalendar1_Click:
    Exit Sub
    Err_CmdCalendar1_Click:
    MsgBox Err.Description
    Resume Exit_CmdCalendar1_Click
    End Sub

    I get:

    "invalid call or procedure argument".

    Yes, I am a novice. Any ideas?

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi

    Blimey - GetObject isn't something for the novices

    When you say you have "(inserted) the calendar without a problem" - what do you mean?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Jan 2006
    Posts
    7
    I insert the control using the toolbox (or "insert" from the menu)...it can be accomplished using either method. The calendar itself is now displayed (beautifully) on my form. I don't want it to display always, only after the user either 1) hits a command button, or 2) establishes focus on a particular field on the form.

    The calendar is a little bulky, and I do not want the user to struggle with the date format in the field. As I said, I'm trying to make this idiot-proof for end users that have little or no Access experience.

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Super. In that case -
    1) Check the name of your calendar control
    2) Change your code to something like:
    Code:
    Private Sub CmdCalendar1_Click()
    On Error GoTo Err_CmdCalendar1_Click
    
    Me.MyCalendarControlName.Visible = Not Me.MyCalendarControlName.Visible
    
    Exit_CmdCalendar1_Click:
    Exit Sub
    
    Err_CmdCalendar1_Click:
    MsgBox Err.Description
    Resume Exit_CmdCalendar1_Click
    End Sub
    This will toggle the calendar visibility on each click of the button. Any good?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Jan 2006
    Posts
    7
    I get:

    Method or data member not found

    referring to "MyCalendarControlName"

    Should the control name be the same as the command button name, or MSCAL.OCX, or what?

    And thanks, by the way, for your speedy assistance!

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    1) Open your form in design view
    2) Select the calendar control
    3) Bring up its property sheet and look up the name property value (for example, "Calendar1")
    4) In your code change MyCalendarControlName to the name property value.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Jan 2006
    Posts
    7
    Very, VERY groovy! One more question...since the button toggles the calendar, what control do I set to make it invisible unless the button is clicked? In other words, my calendar wants to load automatically when the form opens.

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Simple - go back to your properties sheet and change the Visible property to False
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Jan 2006
    Posts
    7
    You are the bomb. Thanks again!

Posting Permissions

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