Results 1 to 7 of 7
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    On Change or Before Update? MessageBox

    Should I put my code on the OnChangeEvent or the BeforeUpdateEvent? If user changes the Bank information!



    Private Sub Bank_Change() 'Purpose: User changes bank information.
    If MsgBox("WARNING: This could have adverse effects,Are you sure ?", vbYesNo) = vbNo Then
    Me!Bank.Undo
    End If

    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    "The Change event occurs when the contents of a text box or the text portion of a combo box changes. It also occurs when you move from one page to another page in a tab control."
    You cannot cancel the change event.

    You CAN cancel the before update event. You would have to add a line to the code:

    CANCEL = TRUE


    There are two different before update events: a Form and a Control:

    Private Sub Form_BeforeUpdate(Cancel As Integer)

    Private Sub controlname_BeforeUpdate(Cancel As Integer)

    It depends on WHEN you want to ask if the change should be saved..

    To be sure, you should look at the events in help..

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    So, it is better left as is using the OnChangeEvent... My code works.... Thanks.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    NO!!! NO!!! NO!!!

    EVERY time you type a letter/number the change event fires.
    So if you are changing the bank info and you have to delete/enter 5 characters, the change event will fire 5 times!!!

    Do you really want to answer the question 5 times???


    If you want to ask before you leave the control, I would use the control before update event:

    Code:
    Private Sub BANK_BeforeUpdate(Cancel As Integer)

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    the way my code is it only asks once unless you keep typing and trying to change it. I think the user will catch on after the first time. especially when it undoes what they just did unless they answer yes and then they can edit. Thanks though, I see your point.

    MY code is on the ONCHANGEEVENT not the before... Just was asking,, so asked and answered. Thanks,,,

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Great.. as long as you can live with the results

  7. #7
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    NO, you were right, that will not work! Had to move the code.

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

Similar Threads

  1. Help using update query to change dates
    By goingcrosseyed in forum Queries
    Replies: 1
    Last Post: 12-03-2012, 07:17 AM
  2. MessageBox Based on Recordset Count
    By Two Gun in forum Forms
    Replies: 3
    Last Post: 12-25-2011, 07:54 AM
  3. record update when I change view
    By mdpepper1 in forum Forms
    Replies: 1
    Last Post: 11-02-2011, 07:50 AM
  4. messagebox help :D
    By imintrouble in forum Forms
    Replies: 2
    Last Post: 10-20-2011, 01:50 PM
  5. Make a messagebox
    By carstenhdk in forum Queries
    Replies: 7
    Last Post: 05-18-2010, 06:18 AM

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
  •  
Other Forums: Microsoft Office Forums