Results 1 to 3 of 3
  1. #1
    Join Date
    May 2013
    Posts
    1

    Angry Unanswered: Form_BeforeUpdate Issue

    Using Windows 7 Professional, Access 2010

    I'm trying to add a prompt after a user selects the "add record" button. The prompt basically asks them if they are sure they want to add, if they select yes, I want a message to display "record added" if they select no, I want a message to display "record not added". The code below is what I am using. I can't get either confirmation messages (record added/not added) to work. The "record not added" portion is not in this example below.

    Any suggestions?

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim strMsg As String
    Dim iResponse As Integer

    ' Specify the message to display.
    strMsg = "You are about to add a new record to the database. Select yes to confirm entry or no to cancel" & Chr(10)

    ' Display the message box.
    iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "**Warning**")

    ' Check the user's response.
    If iResponse = vbNo Then

    ' Undo the change.
    DoCmd****nCommand acCmdUndo

    ' Cancel the update.
    Cancel = True

    End If

    ' Confirm record was entered.
    If iResponse = vbYes Then

    'Specify message to display.
    strMsg = "Record entered" & Chr(10)

    End If
    End Sub

  2. #2
    Join Date
    Jan 2005
    Posts
    146
    You need to place this code in the Before Insert if you want to be able to cancel the record. If the user wants to cancel the record:

    Cancel = 1
    Me.undo

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by billmeye View Post
    You need to place this code in the Before Insert if you want to be able to cancel the record.
    The BeforeInsert event pops the instant a character is entered into a New Record! How would you expect anyone to decide whether or not to save a Record at this point in time?

    The Form_BeforeUpdate is the proper event for this type of thing!

    The reason your confirmation messages didn't show is that you never coded for them to! You had the messages defined, i.e.

    strMsg = "Record entered" & Chr(10)

    but you never used the message in a Messagebox!

    Try the below and see what happens:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    Dim strMsg As String
    Dim iResponse As Integer
    
    ' Specify the message to display.
    strMsg = "You are about to add a new record to the database. Select yes to confirm entry or no to cancel" & Chr(10)
    
    ' Display the message box.
    iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "**Warning**")
    
    If iResponse = vbNo Then
     Cancel = True
     Me.Undo
     strMsg = "Record Not Entered" & Chr(10)
     MsgBox strMsg
    Else
     strMsg = "Record entered" & Chr(10)
     MsgBox strMsg
    End If
    
    End Sub

    Linq ;0)>
    Last edited by Missinglinq; 05-16-13 at 17:04.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Tags for this Thread

Posting Permissions

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