Results 1 to 9 of 9
  1. #1
    MAM8433 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2011
    Posts
    5

    Understanding afterupdate

    Hi, all:
    I hope you can help this VBA newbie. It's probably rooted in my lack of understanding and experience with Access events.



    I realize that I should not store a calculated variable such as mileage cost (miles * rate) in my cost table. So I am storing Mileage and MIRate (with a default value).

    My form, based on an all-fields query of my cost table, defaults to datasheet view. I would like to display a message box to appear immediately after the user enters mileage so the user can confirm the calculated mileage costs. So I created an afterupdate event:

    Private Sub Mileage_AfterUpdate()
    MsgBox prompt:="Mileage costs = $ " & Mileage * MIRate
    End Sub

    Nothing happens. It won't popup on before update or on change What must I do to get the msgbox to appear? Thanks!

  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,540
    Hi

    Not sure if this will work.

    Private Sub Mileage_AfterUpdate()
    MsgBox prompt:="Mileage costs = $ " & Me.Mileage * Me.MIRate
    End Sub
    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
    MAM8433 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2011
    Posts
    5
    Thanks, Bob It's a matter of getting the message box to pop open. [I did fix as you recommended and it still won't display.]

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I'm not sure about your syntax; perhaps something like the following. Once you have the verification or not, you have to do something with it (I assume). In the code below, if the user clicks OK, the code just exits, if they click cancel, it undoes the record, so they have to start over.

    Code:
    Private Sub miles_AfterUpdate()
    Dim holdresp As Long
    holdresp = MsgBox("Mileage Cost= $" & Me.miles * Me.MIRate, vbOKCancel, "Verify Cost")
    If holdresp = 1 Then
        Exit Sub
    Else
        Me.Undo
    End If
    
    End Sub

  5. #5
    MAM8433 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2011
    Posts
    5
    Hi, jzwp11:

    I don't think I need a message box function, when a simple message statement will do. Once the user clicks okay, he/she should return to the datasheet and move on or reconcile. Still, I need to get the box to pop up.

  6. #6
    nicknameoscar is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Apr 2011
    Location
    Earlysville, VA
    Posts
    91
    Put a Debug.print "AfterUpdate ran" in your code and see if "AfterUpdate ran" shows up in your Immediate window in the VBA IDE. This will tell you if the AfterUpdate event is firing.

    If it doesn't fire it might mean your database is not stored in a Access recognized safe location. Do you see the "Security Warning: Certain content in the database has been disabled" message?

    Can you attach the database so users here can look at it?
    Last edited by nicknameoscar; 05-23-2011 at 12:38 PM. Reason: After thought

  7. #7
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Whether or not you need the code to do what I showed. Did you try it to see if the message prompt showed up (in my test database it did)? If it did not show up, then you should probably follow nicknameoscar guidance.

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Hi

    If the AfterUpdate event does not fire you could check that [Event Procedure] has been selected in the AfterUpdate event property sheet.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    MAM8433 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2011
    Posts
    5
    You all are terrfic!

    Nicknameoscar nailed the problem. I have not established a trusted location for the database (but let me assure you that I will do that next). This morning I must have neglected to properly handle the warning message. Truly, a head-slapping I could have had a V-8 moment. Thank you for teaching me what to consider should this EVER happen again. Cheers!

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

Similar Threads

  1. Replies: 5
    Last Post: 09-20-2013, 08:36 AM
  2. Not understanding Running Sum Query
    By dynamictiger in forum Queries
    Replies: 4
    Last Post: 08-30-2010, 11:50 AM
  3. AfterUpdate not updating
    By P5C768 in forum Programming
    Replies: 6
    Last Post: 06-10-2010, 02:31 PM
  4. Understanding SQL Querys
    By jacobbiljo in forum Access
    Replies: 8
    Last Post: 11-17-2009, 05:17 PM
  5. BeforeUpdate and AfterUpdate Question
    By gsurfdude in forum Programming
    Replies: 0
    Last Post: 04-03-2008, 07:56 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