Solved

ActiveX Ctrl -- Calendar

Posted on 2004-10-21
332 Views
Last Modified: 2012-08-13
I added the Calendar object to a form.    When clicking on a ComboBox (DocumentDate), I bring up the calendar and can select a date.

I now have moved the ComboBox ctrl to a tab/page... so far so good.

However, on a second tab/page, I want to call the calendar via a 2nd date combo.   I want the calendar to be positioned at different X/Y coordinates.  So, I ended up inserting a 2nd Calendar control to the 2nd tab.   I also renamed it from "Calendar" to "Calendar2".  

Unfortunately, above does not work (I guess it doesn't recognize "Calendar2").

Okay, I now added the calendar to a stand-alone form that I want to call from either one of the two date combos.  I named the form the calendar resides on "frmCalendar".

Below are 2 sets of functions
1. "OriginalFunctions" (between ===s)
2. "ChangedFunctions" (between ***s)

I get an error though via the "ChangedFunctions" approach.  

So, here is my question... does anyone know how I can call the calendar (frmCalendar) from either date combo on either worksheet (different X/Y coordinates)?


Thanks,
Tom




======= OriginalFunctions=============
Private Sub DocumentDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

  ' Show Calendar and set its date.
   Calendar.Visible = True
   Calendar.SetFocus
   ' Set to today if DocumentDate has no value.
   Calendar.Value = IIf(IsNull(DocumentDate), Date, DocumentDate.Value)

End Sub

Private Sub Calendar_Click()
   ' Set OrderDate to the selected date and hide the calendar.
   DocumentDate.Value = Calendar.Value
   DocumentDate.SetFocus
   Calendar.Visible = False

End Sub
======= OriginalFunctions=============


******* ChangedFunctions*************
Private Sub DocumentDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

  ' Show Calendar and set its date.
   Forms![frmCalendar].[Calendar].Visible = True
   Forms![frmCalendar].[Calendar].SetFocus
   ' Set to today if DocumentDate has no value.
   Forms![frmCalendar].[Calendar].Value = IIf(IsNull(DocumentDate), Date, DocumentDate.Value)

End Sub

Private Sub Calendar_Click()
   ' Set OrderDate to the selected date and hide the calendar.
   DocumentDate.Value = Forms![frmCalendar].[Calendar].Value
   DocumentDate.SetFocus
   Forms![frmCalendar].[Calendar].Visible = False

End Sub
******* ChangedFunctions*************
0
Question by:TomBock2004
    4 Comments
     
    LVL 77

    Expert Comment

    by:peter57r
    Hello TomBock2004,

    I assume you are using an Openform satament to display the calendar and that you have different openform statements for each combo.
    In the Openform statement the last argument is OpenArgs.  You can use this to pass data/info to the form you are opening.
    You could put a value ther which tells the calandar form wher it is being called from.  In the calendar form Open event procedure you can test the value of Openargs and then use whatever positioning code you like (movesize or whatever) to position the form.

    if me.openargs = 1 then
    docmd.movesize 1000, 2000
    else
    docmd.movesize 2000, 5000
    end if


    Pete
    0
     
    LVL 8

    Accepted Solution

    by:
    This example database will show you how to open a form relative to a control.

    http://www.lebans.com/openform.htm
    0
     

    Author Comment

    by:TomBock2004
    Mourdekai:

    Thanks for the link to Stephen's site... the sample works great.

    However, I have some difficulties combining his solution with my attempt to utilize the calendar (which sits on the called form).

    As listed in the original function, when clicking on the combo, the calendar would pop up, I then select a date, and in turn the combo's date is updated.

    Now, I have changed the function to accomodate Stephen's approach.   The form pops up fine but when I click on a date the on "frmCalendar", the date combo on "frmCorrespondence" does not change at all.  

    Do you have any suggestions as to how I pass on the selected value from the frmCalendar to frmCorrespondence?

    Here are the 2 functions:


    *******************************************

    Private Sub DocumentDate_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

        Dim blRet As Boolean
        blRet = PositionFormRelativeToControl("frmCalendar", Forms![frmCorrespondence].[DocumentDate], 2)

        Forms![frmCalendar].[Calendar].Value = IIf(IsNull(Forms![frmCorrespondence].[DocumentDate]), Date, Forms![frmCorrespondence].[DocumentDate].Value)
       
    End Sub

    *******************************************

    Private Sub Calendar_Click()

       DocumentDate.Value = Forms![frmCalendar].[Calendar].Value
       DocumentDate.SetFocus
       Forms![frmCalendar].[Calendar].Visible = False

    End Sub

    *******************************************

    0
     

    Author Comment

    by:TomBock2004
    Raised the points to 500...

    Tom
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Cisco Complete Network Certification Training

    If you’re an IT engineer or technician, it's time you take your career to the next level. This elite training bundle is brimming with all of the information you need to learn to sit for Cisco CNNA, CCNP, and CCENT certification exams.

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

    845 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now