Required Controls in Forms

juniorc

New member
Local time
Yesterday, 19:51
Joined
Aug 25, 2011
Messages
9
Community of Wise Ones

how do I set a bound text box on a form to required. I can find no required property. Must I use Validation Rules property? If so what is the expression that guarntees that the textbox has valid info?
 
I find it strange there is not an explicit "Required" property for a textbox control on a form. Do you know if there is a reason for this? I am trying to learn Access as thoroughly as i can.
 
Because Controls, such as Textboxes, are Controls, they aren't Fields!

A Control is merely an empty box for entering and displaying the data held in a Field.

You can only Require that a Field in a Table be populated.

As Paul said, you can go to Design View for your underlying Table and set the Field there to Required. Most experienced developers, however, don't do this, because the Error Messages that Access generates if a Field is left empty can be very confusing to the users. Instead, they use code, such as this from Paul's example
Code:
If Len(Me.SomeControl & vbNullString) = 0 Then
  MsgBox "You need to fill out SomeControl"
  Cancel = True
  Me.SomeControl.SetFocus
End If
in the Form_BeforeUpdate event. This allows you to display your own error message which, hopefully, will be more understandable to your users.

If you need to Validate that Data was entered in several Controls, you'd do it like this
Code:
If Len(Me.SomeControl & vbNullString) = 0 Then
  MsgBox "You need to fill out SomeControl"
  Cancel = True
  Me.SomeControl.SetFocus
  [B]Exit Sub[/B]
End If

If Len(Me.AnotherControl & vbNullString) = 0 Then
  MsgBox "You need to fill out AnotherControl"
  Cancel = True
  Me.AnotherControl.SetFocus
  [B]Exit Sub[/B]
End If
Notice the added command, Exit Sub. This is needed in Multi-Control validations only.

Linq ;0)>
 
Missinglinq,
Certainly nothing was missing from your response to my question. I appreciate your thoroughness. I had in fact solved the issue much the way your post recommended. Your validation was reassuring.
 

Users who are viewing this thread

Back
Top Bottom