Results 1 to 3 of 3
  1. #1
    NovoRapid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    1

    Skip section of code on button click


    hello,

    I am using the following code to ensure that a new record is not created without the user intending to.

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     'If the form data has changed a message is shown asking if
       'the changes should be saved. If the answer is no then
       'the changes are undone
     
       On Error GoTo BeforeUpdate_Error
      
       If Me.Dirty Then
        'if record has been changed the dirty property
        ' is set to true Display message to save the record
          If MsgBox("The record has changed - do you want to save it?", _
          vbYesNo + vbQuestion, "Save Changes") = vbNo Then
             Me.Undo
          End If
       End If
    BeforeUpdate_Exit:
       Exit Sub
    BeforeUpdate_Error:
       MsgBox Err.Description
       Resume BeforeUpdate_Exit
    
    End Sub
    However, this code is preventing the operation of my "command326" (a run query based on the current field contents button) and "FindRecord" buttons.

    My ultimate goal is to be able to ensure that records are not created inadvertantly while still allowing for the form fields to also be used to search the database.

    Any help would be greatly appreciated.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Why do you 'run query'?

    What happens when you try to find record? What is error message?
    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.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    are you using a bound form? if you are do not use one of your existing bound controls as your search criteria input, instead use an unbound control.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-20-2014, 03:25 PM
  2. Replies: 2
    Last Post: 10-09-2014, 11:37 AM
  3. Replies: 2
    Last Post: 01-09-2014, 07:24 PM
  4. Code to print 'section' of a word document.
    By TurnipGrnPeace in forum Access
    Replies: 6
    Last Post: 06-25-2013, 07:17 PM
  5. Replies: 6
    Last Post: 03-26-2013, 12:17 PM

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