Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calendar Control to Set Forms Dates (2000)

    How can I use the calendar in the startup form of the attached mdb so that I can add new dates to the giorno field in the form's record source as well as updating values in the other two fields of the form's record source by selecting an already present date in the calendar and typing the relevant values in the TXTQT and SALTO text boxes?
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    On the version you post here (main form without subforms), it isn't difficult:

    Private Sub CGior_AfterUpdate()
    Dim strFilter As String
    strFilter = "Giorno = #" & Format(Me.CGior, "mm/dd/yyyy") & "#"
    Me.Filter = strFilter
    Me.FilterOn = True
    Me.Cdata.DefaultValue = "#" & Format(Me.CGior, "mm/dd/yyyy") & "#"
    End Sub

    This selects the date in the form, and sets the default value for the Cdata control to the calendar date, so that if there is no record yet, the correct date will be filled in. But I fear that it won't work if you add back the subforms.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    Ciao Hans, thank you
    Done what you advised me to(please see attachment) but now whenever I try and select a date on the calendar I get:
    Run-time error '3022':
    (translated from Italian) The modifications didn't carry through because you tried to duplicate values in the index, in the primary key or in the relationship. Modify the data in the field(s) that contain the duplicated data, remove the index or redefine the index to allow inserting duplicate items, then try again.
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    You should also change the On Load event. See attached version (stripped down!)
    Attached Files Attached Files

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    Ok Hans, done that(please see attachment) but I still get the error outlined in my previous post whenever I try and select a date on the calendar.
    Attached Files Attached Files

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    Sorry, can't explain that. The form in your latest attachment works OK for me, except for the references to the non-existing subforms. I can select a date in the calendar, enter a value in txtQT, select another date, etc.

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    I can't explain it either! After closing the file and reopening it, it works! <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    And now it works even with the subforms added back in! If you click on the "Gruppo 2" tab on the tab control you'll see there's a "Delete Record" button added, I've written working code attached to the click event of the button to delete the record selected through the calendar on the main form.
    I was just curious Hans, I've noticed the CurrentRecord property of forms, do you know how one could use it in place of the code for the "Delete Record" button to delete the currently selected record?
    Attached Files Attached Files

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    Giorgio,

    CurrentRecord is just a number - it corresponds to the number you see between the navigation buttons at the bottom of a form (if you display those). To delete the current record in a form, you can use

    RunCommand acCmdDeleteRecord

  10. #10
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    Thank you Hans,
    When I select a date on the calendar, I'd like the ORA_LET text box in either of the subforms to remain empty if the value in the LETTUR text box is null, otherwise be set at 24.
    I've tried to add the following code to the AfterUpdate event of the calendar but it doesn't work, can you please help? <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    If IsNull(Me!MG1Dez!LETTUR) Then
    Me!MG1Dez!ORA_LET = Empty
    Else
    Me!MG1Dez!ORA_LET = 24
    End If
    If IsNull(Me!MG2Dez!LETTUR) Then
    Me!MG2Dez!ORA_LET = Empty
    Else
    Me!MG2Dez!ORA_LET = 24
    End If
    If IsNull(Me!MG3Dez!LETTUR) Then
    Me!MG3Dez!ORA_LET = Empty
    Else
    Me!MG3Dez!ORA_LET = 24
    End If
    Attached Files Attached Files

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    You shouldn't put the code for this in the After Update event of the calendar control, but in the Before Update event of each of the subforms. Use Null instead of Empty. But why would you want to set ORA_LET to 24 otherwise? You would overwrite any existing value! Or is that OK?

  12. #12
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    You're right Hans, I hadn't realized setting ORA_LET to 24 would overwrite any existing value <img src=/S/blush.gif border=0 alt=blush width=15 height=15>.
    So I just put(see attachment)
    If IsNull(LETTUR) Then ORA_LET = Null
    in the BeforeUpdate event of each of the subforms but still when I select a date for which LETTUR is Null, ORA_LET is not set to Null. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Attached Files Attached Files

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    The Before Update event only fires if you modify a record. Instead of trying to handle this when you select a date, use update queries to correct the existing records:

    Create an update query based on G1DEZ that selects the records for which LETTUR is Null, and sets ORA_LET to Null. Execute this query.
    Do the same for G2DEZ and G3DEZ.

    When you have done this, there will be no existing records with LETTUR is Null and ORA_LET is not Null any more. The Before Update event ensures that this situation will not arise any more.

  14. #14
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    Thank you Hans,
    Is there a way to set ORA_LET to Null even when there's no underlying record such as when you select, say, March 4, 2004 on the calendar?

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calendar Control to Set Forms Dates (2000)

    I don't understand - if there is no record, there is no value.

Page 1 of 2 12 LastLast

Posting Permissions

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