Frothingslosh
Premier Pale Stale Ale
- Local time
- Yesterday, 22:27
- Joined
- Oct 17, 2012
- Messages
- 3,276
Here's an aggravating situation in Access 2007:
I'm trying to set up a check box on an unbound form (basically a search screen) to, when updated, check to see if a specific text box has data entered, and if it doesn't, cancel the update and revert the change.
Here is the initial code:
The error I receive is:
Setting the value to .OldValue (or setting it directly to FALSE) unsurprisingly causes the following error:
Changing the order of the Undo and the Cancel changes nothing.
The idea here is to cancel the update, revert the change to the value of the control (which will, incidentally, revert it to FALSE in all cases), and move the focus to txtInjuryDate. I just can't seem to get those last three lines to actually WORK, and would be grateful for any suggestions received. Hell, for all I know, it's something simple I'm missing just because I've been beating my head against the wall so long!
I'm trying to set up a check box on an unbound form (basically a search screen) to, when updated, check to see if a specific text box has data entered, and if it doesn't, cancel the update and revert the change.
Here is the initial code:
Code:
Private Sub chkWorkComp_BeforeUpdate(Cancel As Integer)
If IsNull(Me.txtInjuryDate.Value) Then
Beep
MsgBox "Worker's Comp may not be selected unless an injury date has been entered!", vbInformation, PROJECT_NAME
Me.chkWorkComp.Undo
DoCmd.CancelEvent
Me.txtInjuryDate.SetFocus
End If
End Sub
Additionally, the change to the value of the checkbox is NOT reverted. In fact, as far as I can tell, neither the CancelEvent method nor setting Cancel to True do a damned thing, and none of (Undo, Me.Undo, Me.chkWorkComp.Undo) do a bloody thing either - they certainly do NOT revert the checkbox to its prior value, and the control is left unsaved with the focus due to the error, or if I comment out the SetFocus, the control updates as normal despite the Cancel.Run-time error '2108':
You must save the field before you execute the GoToControl action, the GoToControl method, or the SetFocus method.
Setting the value to .OldValue (or setting it directly to FALSE) unsurprisingly causes the following error:
The only surprise there is that it actually DOES revert the change anyway, but will not pass that line in the code.Run-time error '2115':
The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing SRS from saving the data in the field.
Changing the order of the Undo and the Cancel changes nothing.
The idea here is to cancel the update, revert the change to the value of the control (which will, incidentally, revert it to FALSE in all cases), and move the focus to txtInjuryDate. I just can't seem to get those last three lines to actually WORK, and would be grateful for any suggestions received. Hell, for all I know, it's something simple I'm missing just because I've been beating my head against the wall so long!