Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Oct 2011
    Posts
    21
    Thanks
    8
    Thanked 1 Time in 1 Post

    Understanding Form_BeforeUpdate

    I'm at my wits' end here with this. I'm no stranger to VBA, though I am a fledgling in Access. This seems really simple, but I cannot figure out how to fire off Form_BeforeUpdate. This is in Access 2007 with a database created in Access 2007.

    To test when BeforeUpdate fires, I inserted this code under the appropriate form:

    Code:
    Option Compare Database
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim strMsg As String
    
    
    strMsg = ""
    
    MsgBox "Form is about to update", vbOKOnly
    
    End Sub
    I then try to trigger this. I change a field's content and then press PageUp or PageDown to move to the next record. I added a Save Record button and click that. Neither method is causing my code to trigger. I added a lame button with a MsgBox just to verify that my macros are enabled.

    I have this on a subform, but I verified that the code is on the Form_Progress Report form, which is a subform of Form_Student Info. I also opened Form_Progress Report by itself to test it.

    Is there something about Form_BeforeUpdate that I just cannot understand? As far as I can tell, the code should be firing just fine, but I cannot find a reason why it wouldn't. I'm sure it's something obvious but what?

  2. #2
    New Lounger
    Join Date
    Oct 2011
    Posts
    21
    Thanks
    8
    Thanked 1 Time in 1 Post
    Well, I was able to trigger the code when I put it in a different database, so clearly the fault lies in this database, which means I need to upload a copy. I've stripped out any confidential items. It's still a work in progress obviously.
    Attached Files Attached Files

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    OK, I downloaded you db, but which form is causing you the problem, and where is the "lame button" you created?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    New Lounger
    Join Date
    Oct 2011
    Posts
    21
    Thanks
    8
    Thanked 1 Time in 1 Post
    Quote Originally Posted by MarkLiquorman View Post
    OK, I downloaded you db, but which form is causing you the problem, and where is the "lame button" you created?
    I appreciate it.

    I removed the lame button. I created it just to ensure that my macros were enabled.

    The code is contained in Form_Progress Report. That is actually a subform within Student Info, so I would think it would work whether I update the record by having Progress Report open by itself or through Student Info.

  5. #5
    New Lounger
    Join Date
    Oct 2011
    Posts
    21
    Thanks
    8
    Thanked 1 Time in 1 Post
    I do have a Save Record button on Progress Report in case pressing PageUp or PageDown wasn't updating the records. I imagine that button is superfluous, and I don't intend on keeping it in the final version anyway.

  6. #6
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    If you look at the property sheet for form [Progress Report] (btw, you should get out of the habit of embedding spaces in names), you will notice that it doesn't contain anything in the Before Update property. As soon as I specified an [Event Procedure], it found the code you had for displaying a MsgBox. Back in form view, I edited a record, moved to another record, and the MsgBox popped up.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  7. The Following User Says Thank You to MarkLiquorman For This Useful Post:

    Kuildeous (2015-03-04)

  8. #7
    New Lounger
    Join Date
    Oct 2011
    Posts
    21
    Thanks
    8
    Thanked 1 Time in 1 Post
    Quote Originally Posted by MarkLiquorman View Post
    If you look at the property sheet for form [Progress Report] (btw, you should get out of the habit of embedding spaces in names), you will notice that it doesn't contain anything in the Before Update property. As soon as I specified an [Event Procedure], it found the code you had for displaying a MsgBox. Back in form view, I edited a record, moved to another record, and the MsgBox popped up.
    Oh wow, it is really just that easy. I had it set to [Event Procedure] at some point and apparently cleared it during my mucking about. Add to that the fact that I'm not used to calling code via properties. I've done most of my VBA in Word, and I treated the Form codes the same as AutoOpen. I'll be more vigilant in checking the event properties.

    And point taken on the naming structure. I knew that deep down, but it's so easy to revert to natural names.

Posting Permissions

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