Zydeceltico
Registered User.
- Local time
- Today, 15:22
- Joined
- Dec 5, 2017
- Messages
- 843
Hi all -
I have a form that has three controls (2 cbos and 1 textbox) that are bound to 3 required fields. There are several other controls on this form but they are not required. I also have a save button for the form (and another underlying form).
The problem is that it is easy to click the "Save" button without filling in all three fields which of course throws an error and junks out the form maing it a real pain.
The button's save code is this:
This code is on the form's BeforeUpdate:
I already know the above code is not what I am after exactly......
What I really want is code to put on the BeforeUpdate of the form so that if the user accidentally clicks the save button before the required fields all have values the BeforeUpdate code tests to see if any of the 3 required controls are dirty; if any but not all are dirty a msgbox opens to to tell the user "hey - you still need to fill in x or y or x and y" - and most importantly does not crash the form into the save code from the button click which throws a Run-time error 2501 after it pops up my custom message. The run-time error occurs on this line of the Save code:
I'm pretty sure this is a common type of test to do but I'm having trouble finding an example that I can abscond with.
Any direction or insight would be appreciated and put to very good to use!
Thanks,
Tim
I have a form that has three controls (2 cbos and 1 textbox) that are bound to 3 required fields. There are several other controls on this form but they are not required. I also have a save button for the form (and another underlying form).
The problem is that it is easy to click the "Save" button without filling in all three fields which of course throws an error and junks out the form maing it a real pain.
The button's save code is this:
Code:
If CurrentProject.AllForms("frmInspectionEvent").IsLoaded Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
Forms!frmInspectionEvent.Requery
Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
End If
This code is on the form's BeforeUpdate:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If (IsNull(Me.cboLine1Workstation)) And (IsNull(Me.cboLineStopReason.Value)) Then
' No action required
Else
If (IsNull(Me.txtLineStopBegin)) Or (Me.txtLineStopBegin.Value = "") Then
MsgBox "You must provide data for field 'Line Stop Start', " & _
"if a value is entered in Line 1 Workstation", _
vbOKOnly, "Required Field"
Me.txtLineStopBegin.SetFocus
Cancel = True
Exit Sub
End If
End If
End Sub
I already know the above code is not what I am after exactly......
What I really want is code to put on the BeforeUpdate of the form so that if the user accidentally clicks the save button before the required fields all have values the BeforeUpdate code tests to see if any of the 3 required controls are dirty; if any but not all are dirty a msgbox opens to to tell the user "hey - you still need to fill in x or y or x and y" - and most importantly does not crash the form into the save code from the button click which throws a Run-time error 2501 after it pops up my custom message. The run-time error occurs on this line of the Save code:
Code:
If CurrentProject.AllForms("frmInspectionEvent").IsLoaded Then
[COLOR="Red"][B]DoCmd.RunCommand acCmdSaveRecord[/B][/COLOR]
DoCmd.Close
I'm pretty sure this is a common type of test to do but I'm having trouble finding an example that I can abscond with.
Any direction or insight would be appreciated and put to very good to use!
Thanks,
Tim