• Understanding Form_BeforeUpdate

    Author
    Topic
    #498874

    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?

    Viewing 2 reply threads
    Author
    Replies
    • #1493377

      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.

      • #1493382

        OK, I downloaded you db, but which form is causing you the problem, and where is the “lame button” you created?

        • #1493391

          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.

    • #1493392

      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.

    • #1493418

      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.

      • #1493511

        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.

    Viewing 2 reply threads
    Reply To: Understanding Form_BeforeUpdate

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: