Results 1 to 4 of 4
  1. #1
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    254
    Thanks
    6
    Thanked 1 Time in 1 Post

    UnLoad before Close (Access XP)

    <font color=ff8c00>Saw some things similar in search but not the same.</font color=ff8c00>

    I have a form where hours are entered. When the form is closed, it writes the current record; even if the hours are blank.

    I want to prevent a write at all if the close button is clicked. I have already prevented a update with a warning if hours are zero (0).

    Is unload the answer? I do not want blank records.
    Alan

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

    Re: UnLoad before Close (Access XP)

    AFAIK, you can't prevent the current record being saved in the On Unload or On Close event of a form. The On Unload event procedure has an argument Cancel, but that can be used to prevent the closing of the form. To prevent a record from being saved, you must set Cancel = True in the Before Update event procedure.

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

    Re: UnLoad before Close (Access XP)

    In the BeforeUpdate event of the form, test for blank fields that should contain data. If those fields are blank, use Me.Undo to roll back the update. You don't need to Cancel in that case. You would make it easier on yourself if you indexed the table to prevent nulls in the fields you need to have filled in.
    Charlotte

  4. #4
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UnLoad before Close (Access XP)

    In circumstances such as these I collect data through unbound text boxes (or other types of control) on an unbound form with Save and Cancel buttons.

    When the Save button is clicked the underlying code checks the data for validity and then writes the data direct to the underlying tables before exiting. The Close button simply closes the input form without saving.

    The advantage of using unbound input forms is better control of validation and saving of data. The data is only saved when you want to.

Posting Permissions

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