I have some code on a form that asks you if you want to save the changes to the record before moving on to the next record or closing the form. The code is in the form's BeforeUpdate event. This is what I have currently:
This works. However, the acCmdSave is very slow; usually about 2 - 3 seconds. However, I also have a Save button that uses:
This works in about .25 - .5 seconds. My idea was to use this same code in the form's BeforeUpdate event in place of the DoCmd.RunComman d acCmdSave. When I do, I get the following error message:
Run-time error '2115':
The macro of function set to the BeforeUpdate or ValidationRule property for this field is preventing IT Inventory from saving the data in the field.
I checked and there is no validation rule on the field that was changed. Here is the entire BeforeUpdate event:
Just to let you know, intSaved is publicly declared at the top of the form's VBA page. I use it to know if the Save button has been clicked (which sets the variable to 1).
What is wrong with my code?
Code:
If intResponse = vbCancel Then
DoCmd.RunCommand acCmdUndo
Else
Docmd.RunCommand acCmdSave
End If
Code:
If Me.Dirty = True Then Me.Dirty = False
Run-time error '2115':
The macro of function set to the BeforeUpdate or ValidationRule property for this field is preventing IT Inventory from saving the data in the field.
I checked and there is no validation rule on the field that was changed. Here is the entire BeforeUpdate event:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim intResponse As Integer
If intSaved = 0 Then
strMsg = "you have made one or more changes to this Record. Do you wish to save this record" _
& "with those changes?" & vbCrLf & vbCrLf & "Click OK to save changes, or Cancel to" _
& "Undo these changes."
intResponse = MsgBox(strMsg, vbQuestion + vbOKCancel + vbDefaultButton1, "Prompt to Save Record")
If intResponse = vbCancel Then
DoCmd.RunCommand acCmdUndo
Else
'DoCmd.RunCommand acCmdSave
Me.Dirty = False
End If
Else
intSaved = 0
End If
End Sub
What is wrong with my code?
Comment