Skip Form_Before_Update

kbreiss

Registered User.
Local time
Today, 17:27
Joined
Oct 1, 2002
Messages
228
Is there away to skip Form_Before_Update? I have a command button (cmdOK) that I use when the user adds a record. My problem is the code runs to add for cmdOK when clicked and then it runs again following immediately. I'm wondering if I could put something in the cmdOK_Click that after it gets done updating it quits running the program and skips the "Form_Before_Update" Any advice would be appreciated.

Private Sub cmdOK_Click()

If cboAction.ListIndex = 1 Then 'save record if add
MsgBox txtFacilityName & " Added."
DoCmd.SetWarnings (False)
DoCmd.Save acForm, "frmFacility"
DoCmd.RunCommand acCmdRefresh
strDocName = "qryAddInfo"
DoCmd.OpenQuery strDocName, acNormal, acEdit
cboAction.Requery
DoCmd.GoToRecord acForm, "frmFacility", acNewRec
'WOULD LIKE SOMETHING HERE THAT STOPS IT FROM RUNNING ANYMORE CODE
End If


Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("Save Changes to " & txtFacilityName & " ?", vbQuestion + vbYesNo, "Save?") = vbYes Then
DoCmd.SetWarnings (False)
If cboAction.ListIndex = 1 Then
strDocName = "qryAddInfo"
DoCmd.OpenQuery strDocName, acNormal, acEdit
Me.Undo 'keeps from getting an error...doesn't try to save the record twice.

End If
Else
Me.Undo
End If

End Sub
________
HERBAL HEALTH SHOP
 
Last edited:
I'm not sure why you are running a query if your form is bound.
DoCmd.Save acForm, "frmFacility"
- does NOT save the current record. It saves the referenced form. You should NEVER be modifying a form object so I'm guessing that your intention is to save the current record.
DoCmd.RunCommand acCmdSaveRecord saves the current record. This code will cause your Before and AfterUpdate events to run so don't write code in this event that duplicates code you have in the BeforeUpdate event. Put ALL your update related code in the BeforeUpdate event. Then, if you want to force the BeforeUpdate event to be executed, you can use the save record code I noted above.
 
All of my fields are bound EXCEPT my username field which I get from a module. So I was thinking that and insert statement was the only way to get the username into the record. I tried doing the DoCmd.RunCommand acCmdSaveRecord then doing an update statement so I could insert the username but nothing is saving. Do you have any suggestions? I also am receiving a "The command or action "Save Record" isn't available now.

Thanks,
Kacy
________
Paxil settlements
 
Last edited:
To change the value of a field in your RecordSource, you just need a line of code that looks like this:

Me.UserName = Me.UserNameControl

The UserName field needs to be in the query or table that the form's RecordSource refers to but it does not need to be bound to a control on the form, although it could be.

You should put the above line of code in the FORM's BeforeUpdate event. That way every time data on the form is changed, the user who changed it will be logged in your table.
 

Users who are viewing this thread

Back
Top Bottom