Required Field

vaughan198

Registered User.
Local time
Yesterday, 22:57
Joined
Nov 16, 2011
Messages
40
Hi there,
I have a text box on a form that I want to be required if a checkbox is ticked. I dont want to make the field in the table requried as it depends on the checkbox.

I can use this code to make the field enabled when the check box is selected:

Code:
Private Sub chkbox_Click()
If chkbox = True Then
Box.Enabled = True

Else
Box.Enabled = False
End If
End Sub

But if I use Box.Required = True then I get errors.

Is there anyway to do this?

Thanks
 
I would use the Unload event of the form to check that all needed data has been supplied. If the required data has not been entered the Unload event can be Cancelled and the user directed back to the textbox.
 
I would use the Unload event of the form to check that all needed data has been supplied. If the required data has not been entered the Unload event can be Cancelled and the user directed back to the textbox.

Sorry Bob, but you probably mean BEFORE UPDATE event. If you get to the form's UNLOAD event, any changes have already occurred and it is too late for data validation. The BEFORE UPDATE event is where to check.
 
I would use the Unload event of the form to check that all needed data has been supplied...
And if the users enters multiple Records before closing the Form? How would you check all of those Records for the Required data?

No, Validation Code that relates to a Field being populated has to be in the Form_BeforeUpdate event, which fires just prior to a Record being saved:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
 If Me.CheckBoxName = True And Nz(Me.TextBoxName, "") = "" Then
  MsgBox "When CheckBoxName is Ticked There Must Be a Value in TextBoxName!"
  Cancel = True
  TextBoxName.SetFocus
 End If
End Sub
Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom