Thread: mandatory checkbox
07-19-12, 13:04 #1Registered User
- Join Date
- May 2012
Unanswered: mandatory checkbox
I have a checkbox on my main form. This checkbox is to be mandatory on save and close. If this checkbox has not been checked then an error message is supplied and it goes to the field I assigned to setfocus. This does work on save. However if I go to close and the checkbox hasn't been checked then it will supply the error message then close. Does not go to the designated setfocus field. You can't setfocus to a checkbox right?
Thanks in advance
07-19-12, 18:17 #2Moderator
Provided Answers: 19
- Join Date
- Jun 2005
- Richmond, Virginia USA
I'm confused! What is the point of having a Checkbox Control that has to have one and only one given Value, i.e has to be equal to True/Yes/-1, before the Record can be saved?
That aside, you have to Cancel the save before returning Focus to the Checkbox. in general terms, Validation code to check Controls before saving a Record should be something like this:
Private Sub Form_BeforeUpdate(Cancel As Integer) If Me.CheckboxName <> -1 Then MsgBox "CheckboxName Must Be Ticked Before Saving Record!" Cancel = True CheckboxName.SetFocus Exit Sub End If End SubHope this helps!
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007