Results 1 to 4 of 4
  1. #1
    xwnoob is offline Advanced Beginner
    Windows Vista Access 2000
    Join Date
    Nov 2011
    Posts
    76

    Can someone help me add an exception argument to my cancel as integer sub?

    So i have this code:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.Dirty Then
    'Ensure that users do not accidentally save records
    If MsgBox("Do you want to save the updated records?", vbOKCancel, "Save?") = vbCancel Then


    Me.Undo
    End If
    End If
    End Sub

    How do i add a code inside that creates an exception for a button that goes to a new record? I want to add the exception for my add new record button but i dont know which function/command to use

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    First off, if the Before Update event fires, the form is dirty so you don't need to check that. Second, do you want it to save when the new record button is clicked but not if it is navigated to in another way? Or what?

  3. #3
    xwnoob is offline Advanced Beginner
    Windows Vista Access 2000
    Join Date
    Nov 2011
    Posts
    76
    Quote Originally Posted by boblarson View Post
    First off, if the Before Update event fires, the form is dirty so you don't need to check that. Second, do you want it to save when the new record button is clicked but not if it is navigated to in another way? Or what?
    Yes i would like it to save when the new record button is clicked but not any other way thats why i did the me.undo. My form has 2 subforms on it and i intend to add a new record button to each of them so that the only way you can save the records are to click on the buttons

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You can set a flag for the Before Update event by putting this:

    Code:
    Private blnSave As Boolean
    in the general declarations section of the form's code (that is up after the OPTION COMPARE DATABASE and, if you have it set, the OPTION EXPLICIT).

    then you would set it to TRUE in the click event of the form's save button:

    Code:
    Private Sub YourButtonNameHere_Click()
       If Me.Dirty Then
          blnSave = True
          Me.Dirty = False
       End If
       
    End Sub
    Then in the form's BEFORE UPDATE event you would use:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
       Cancel = (Not blnSave)
    End Sub

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

Similar Threads

  1. Exception in unique field
    By neo651 in forum Access
    Replies: 2
    Last Post: 07-01-2011, 02:23 PM
  2. An Unhandled win32 exception occurred in MSAccess.exe
    By Alice Liu in forum Import/Export Data
    Replies: 2
    Last Post: 12-08-2010, 01:40 PM
  3. Adding column as INTEGER makes it a long integer?
    By luckycharms in forum Programming
    Replies: 2
    Last Post: 10-20-2010, 02:47 PM
  4. Exception Reporting - Continued
    By shexe in forum Queries
    Replies: 11
    Last Post: 09-20-2010, 11:20 AM
  5. Exception Reporting
    By shexe in forum Queries
    Replies: 16
    Last Post: 09-09-2010, 09:14 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