How Can I Branch To The BeforeUpdate Event?

Curious

Registered User.
Local time
Today, 16:15
Joined
Oct 4, 2005
Messages
53
I have setup all my form validation in the BeforeUpdate event.

I know that Access will auto save the current record when you scroll to the next record, which works fine with my BeforeUpdate validation code.

However, some users users just like pressing the "Save" button, becuase it makes them feel confident the records they are entering are being recorded.

So I've included a "Save" button (using the button Wizard).

However, rather than copying all my form validation code from the BeforeUpdate event to the OnClick event of my Save button, I just thought I could branch to the BeforeUpdate event before running the save command.

Here's my code idea:

Code:
Private Sub btnSaveRecord_Click()
On Error GoTo Err_btnSaveRecord_Click

    'GoTo Form_BeforeUpdate - validatebeforesaving
    
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    
    Me.Refresh

Exit_btnSaveRecord_Click:
    Exit Sub

Err_btnSaveRecord_Click:
    MsgBox Err.Description
    Resume Exit_btnSaveRecord_Click
    
End Sub
 
You could: Put the name of the procedure before the save statement.
Code:
<control>_BeforeUpdate
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
You should: Make a function which checks your input and call it from both your BeforeUpdate event as your btnSaveRecord_Click() procedure.
Code:
public function CheckInput() as boolean
'bla
end function

private sub [control]_BeforeUpdate()
    if checkInput then 
        'Oke
    else
        'not oke
    endif
end sub

private sub btnSaveRecord_Click()
    if checkInput then 
        'Oke
    else
        'not oke
    endif
end sub
HTH Guus
 

Users who are viewing this thread

Back
Top Bottom