Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169

    Unanswered: Calendar Control

    I want to have a form with a calendar on it, i want to be able to call the form from anywhere in the database on anyother form and when i select a date then it inputs the date into the date field on the other form...

    Does anyone have any idea how to do this?

    Ive seen it done before, Im just confused about the way to achieve it.

    Ive tried just open form and then set the field to the calendar.value but it only sets the date to the first value that the calendar opens on and not any other that i select?

    I am using Access 2000

    I hope ive explained myself well...
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

  2. #2
    Join Date
    Aug 2002
    Location
    Northampton, England
    Posts
    266

  3. #3
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    Sorry that isnt what i want, i want to be able to acheive the date selection in any form, so if i have a calendar on every form then have a pop up form with a calendar on it that can tell where the date needs to go.

    I dont want to create 20 forms with a calendar on it, just one form that can be called from any form and the date be filled in on that form?
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

  4. #4
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    Ok i have an idea, this might not be the right way to go about it but here goes anyway

    Create a new form and add the caleder control to it
    Open the tool box then click on the button that looks like a tool box to give you more options, this will give you a calender control here

    create a new module and store a global variable in it like this

    Public ctrlCaller As Control

    on each control you want the calender to be able to add values to add code like this

    Code:
    Private Sub Text0_Enter()
        Set ctrlCaller = Me.Text0
        DoCmd.OpenForm "form1"
    End Sub
    and finally add some code to your calender control like this
    Code:
    Private Sub Command1_Click()
        myvar = Me.cal.Value
        ctrlCaller.Value = cal.Value
        Set ctrlCaller = Nothing
        DoCmd.Close acForm, Me.Name
    End Sub
    
    Private Sub Form_Close()
        Set ctrlCaller = Nothing
    End Sub
    
    Private Sub Form_Load()
        cal.Value = Date
    End Sub
    Hope this makes sense
    Dave

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    see my way of doing EXACTLY what you are looking for here in the post of 1/1/05

    izy
    currently using SS 2008R2

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Calendar

    Create a text control on your calendar form (call it: FormCalledFrom) and say the calendar pop up form is called: CalPopUp.

    Say you have a form called: ScheduleForm. It has a field called: DateFieldToPopulate and also has a button to open the CalPopUp form. Your code when the button is clicked would look like this:

    Docmd.openform "CalPopUp"
    Forms!CalPopUp!FormCalledFrom = "ScheduleForm"

    Have a field on the CalPopUp form which is populated with what date the user clicks on in the calendar control (say it's called CalendarDateField.) Have a button called "Insert Date" on your CalPopUp form. Once clicked, the code would look like this:

    Forms(Me!FormCalledFrom)!DateFieldToPopulate = Me!CalendarDateField
    docmd.close acform, "CalPopUp"

    Now say you have another form called: Schedule2Form which also has a date field called: DateFieldToPopulate on it and a button which when clicked has code like this:

    Docmd.openform "CalPopUp"
    Forms!CalPopUp!FormCalledFrom = "Schedule2Form"

    Hope this is what you're looking for.

  7. #7
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Calendar

    Just as a side note: Say your calendar control is called: ActiveXCt10 on the CalPopUp form.

    You would have code in the form: CalPopUp like this (in reference to my suggestion above.)

    Private Sub ActiveXCt10_Click()
    Me!CalendarDateField = ActiveXCt10
    End Sub

    When the user clicks a date in the calendar, you should see that date reflected in the CalendarDateField control.

    If you want to get fancy, you can do something like this in the Form_Load event of the CalPopUp form:

    Me!ActiveXCt10 = Date
    Me!CalendarDateField = Date

    Also, format the field: CalendarDateField as a ShortDate (or LongDate).

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    Paul

    mine is soooo much simpler: let the CalPopUp form do it's own work and discover who called it with
    Screen.ActiveForm.ActiveControl
    in the _Load() of CalPopUp

    it handles an arbitrary number of forms, each with an arbitrary number of date-fields, and without the need for ugly setup code in each datebox _click()

    ...and i also suspect mine will be faster since it doesn't need to trawl through the Forms collection with the setup code.

    izy
    Last edited by izyrider; 01-29-05 at 14:33.
    currently using SS 2008R2

  9. #9
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Calendar

    I wouldn't necessarily call your code soooo much simplier IzyRider (sorry to disagree even though your code does allow him to have more than 1 date field to populate on a single form where my code is based on just having 1 date field to populate on each form). I don't like though dimensioning any variables in the opening of the form which adds overhead in a network type environment (although I'll agree with you that it is a small overhead (except dimensioning the variant) - but add that to a citrix type environment with limited memory and lots of users and lots of Access applications being opened....)

    I agree that the Screen.ActiveForm.ActiveControl can be used. Either way, it looks like ChrisGolden has a couple of different options now on how he wants to do it.

    Take care IzyRider.

Posting Permissions

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