Results 1 to 8 of 8
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    form update

    All, using access 2010 I have a form that users can enter data or search by a combo box to review information about the record. If they make a change to an existing record; I want to have a prompt stating that they have made a change; are you sure you want to save the record or discard the changes. My decision making problem is where to put the code. The users have several ways to search to move to another record therefore they are not always closing the form to move to the next record. I don’t want them to be able to move to another record by searching and changing a record by mistake. I hope I’ve made clear what I’m asking in order for you to assist me. I’ve seen such before but can’t think how to make this happen. Thank you

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Data validation should be done in the forms Before Update event which can be cancelled.
    Sounds like you would need to check the forms Dirty property.
    Post back if you need help with the actual code.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Maybe something like this:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim message As String
    message = "You have made changes to this record.  Are you sure you would like to save?"
    If MsgBox(message, vbQuestion + vbYesNo) = vbNo Then
    Cancel = True
    End If
    End Sub
    Will this work anytime they change the form? I don't want to annoy them when they create a new record; just change existing records. This is because some users don't pay attention and they start typing and move on causing a change; sometimes drastic to the record they are viewing. Thanks

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Yes, it will run with new record.

    Try:

    If Not Me.NewRecord Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Im getting an error when i click no to saving the record. "The setting you entered isn't valid for this property." Also each time I click on a different section of the record; say another subform; it gives me the question. I may want that but havent thought it through. This is the code: What am I doing wrong?
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim message As String
    If Not Me.NewRecord Then
    message = "You have made changes to this record.  Are you sure you would like to save?"
    If MsgBox(message, vbQuestion + vbYesNo) = vbNo Then
    Cancel = True
    End If
    End If
    End Sub

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Which line does the debugger stop on?

    Maybe after the Cancel:
    Me.Undo
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    O I have code on the close button also that I think is interferring:

    Code:
    If Me.Dirty Then Me.Dirty = False
    DoCmd.Close
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Exit_ExitToSwitchboard_Click:
        Exit Sub
    It's referring back to that.

    So; My form has several subforms. The beforeupdate only fires when I change fields on the form. Ok. I don’t want users to accidentally change any fields. I don’t know how to prevent them from doing this since it is a data entry form also. I am noticing that the “before update” code fires when I change a field on the form. If I click no; the focus jumps back to the field I changed. If I keep saying no; it won’t let me proceed until I click yes. If I click yes; it will let me proceed to the next record as long as I don’t hit close. This is when it gives me the error. What do I do and where do I put the code?

  8. #8
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    I wonder about having a close before you open the other form. I'd expect those would have to happen in the other order.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-10-2012, 07:01 AM
  2. Replies: 7
    Last Post: 09-21-2012, 11:09 AM
  3. Replies: 3
    Last Post: 09-20-2012, 11:23 AM
  4. Replies: 0
    Last Post: 05-09-2010, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums