I'm using bound forms for the user to update information on new or existing customers. Right now I'm using a Add New Record macro on the submit button (because I'm not sure how to add or save a new record through VBA).
I added a before update event (using VBA) to have the user confirm they want to save changes before exiting the form. For some reason this is overriding the add record button and now users cannot add new record until exiting the forms.
How can I use VBA to add new customer information to the correct table? Is this something that should be done with macros instead?
Form BeforeUpdate Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strmsg As String
strmsg = "Data has been changed."
strmsg = strmsg & " Save this record?"
If MsgBox(strmsg, vbYesNo, "") = vbNo Then
DoCmd.RunCommand acCmdUndo
Else
End If
End Sub
Add Record Button:
Private Sub btnAddRecord_Click()
Dim tblCustomers As DAO.Recordset
Set tblCustomers = CurrentDb.OpenRecordset("SELECT * FROM [tblCustomers]")
tblCustomers.AddNew
tblCustomers![Customer_ID] = Me.txtCustomerID.Value
tblCustomers![CustomerName] = Me.txtCustomerName.Value
tblCustomers![CustomerAddressLine1] = Me.txtCustomerAddressLine1.Value
tblCustomers![City] = Me.txtCity.Value
tblCustomers![Zip] = Me.txtZip.Value
tblCustomers.Update
tblCustomers.Close
Set tblCustomers = Nothing
DoCmd.Close
End Sub
.OldValue
property? That's the only way I know to uncommit a bound field, as the edits are saved to the table as soon as you exit a control. So without.OldValue
you are triggering your routine too late, and would probably need to be added to the BeforeUpdate event of each control, not on the form. Post the code for your submit button and beforeupdate event to clarify. – MoondogsMaDawg