Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Force User to Save a Record (Access 2000 SP3)

    Access automatically saves changes to the record when you close the form. However, I would like to force the user to either save or cancel changes made in any field in a form before closing. The aim of this is to prevent users from accidentally changing something they didn't mean to change and to give them a "second chance".

    I have seen this done in other Access databases, but I don't know how to implement it in my own. I am not so crash-hot on code, so if that is what is required, I'll need step-by-step instructions!

    Thanks.

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Force User to Save a Record (Access 2000 SP3)

    It is relative simple. Just declare a module level variable, something like:
    Dim AllowToSave as Boolean

    In your form's Current event, place: AllowToSave = False

    In your Save button's Click event, place: AllowToSave = True

    In your form's BeforeUpdate Event, just check status of AllowToSave, and Cancel Update if it is False.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

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

    Re: Force User to Save a Record (Access 2000 SP3)

    The most safe way to do this is to create an unbound form (i.e. a form whose Record Source is blank), but that requires a lot of code. A simpler solution is as follows:
    <UL><LI>Open the form in design view.
    <LI>Activate the Event tab of the Properties window.
    <LI>Click in the Before Update event.
    <LI>Select [Event Procedure] from the dropdown list.
    <LI>Click the builder button, i.e. the ... to the right of the dropdown arrow.
    <LI>The code module belonging to the form will be opened in the Visual Basic Editor, with the "skeleton" of the event procedure already created for you.
    <LI>Make it look like this (you can copy and paste the code if you like)
    <code>
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If MsgBox("Do you want to save changes?", vbYesNo + vbQuestion) = vbNo Then
    Me.Undo
    End If
    End Sub
    </code>
    You can modify the text of the question, of course.
    <LI>Switch back to Access (Alt+F11)
    <LI>Save the form.[/list]The "Do you want to save changes?" prompt will only be displayed if the record has actually been modified.

  4. #4
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force User to Save a Record (Access 2000 SP3)

    Thanks for the tips. I'll try them out.

    Much appreciated,

    Joe

Posting Permissions

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