Form with tabs

G

Guest

I have a form with 5 tabs and I currently have several issues:
1) users are not filling out all the fields on the main form which are used
to link the data in the tabs (5 different tables) I've put checks on the
main form to prompt if a field is left blank as the user moves through the
main form
2) how can I make sure that nothing is entered on any of the tabs if the
main form is not completely filled out?
3) How can I make sure that all the questions on a tab are answered before
the user can go to another tab?

Thanks
 
B

BruceM

The main form's After Update event is a good place to check the various
fields to be sure they contain values. You could hide the tab control, and
make it visible if all of the required fields have been filled in. Perhaps
you could use a "Submit" button or some such thing to save the record on the
main form, and use the form's Before Update event to make the tab control
visible is the required fields have been completed.
In similar fashion you can use the Before Update event of the forms on the
tabs to be sure the required fields have been completed.
Validation code in the form's Before Update event may be something like:

If IsNull(Me.FirstName) Then
MsgBox "You forgot the first name"
Me.txtFirstName.SetFocus
ElseIf IsNull(Me.LastName) Then
MsgBox "You forgot the last name"
Me.txtLastName.SetFocus
End If

This is just one idea. There are lots of ways to go about this. For
instance, you may decide not to hide the tabs. You can still use validation
code. Or you can give the users a chance to bail:

If IsNull(Me.FirstName) Then
If MsgBox ("You forgot the first name." & _
"Click Cancel to exit without saving", vbOKCancel) = vbCancel
Me.Undo
Else
Me.txtFirstName.SetFocus
Cancel = True
End If
ElseIf IsNull(Me.LastName) Then
If MsgBox ("You forgot the first name." & _
"Click Cancel to exit without saving", vbOKCancel) = vbCancel
Me.Undo
Else
Me.txtLastName.SetFocus
Cancel = True
End If
End If

Note that if you decide to hide the tab control you will need code in the
form's Current event to hide the tab control if it is a new record, but show
it for existing records:

If Me.NewRecord Then
Me.TabControlName.Visible = False
Else
Me.TabControlName.Visible = True
End If

If a field is required, you should probably set its Required property to Yes
in table design view. The form's validation code is a convenient (and
potentially user-friendly) way to remind users about required fields that
need values, but is not a substitute for table-level requirements. You can
use table-level validation rules, but it is probably easier for the user to
respond to a form-level error message (in this case, one generated in the
Before Update event).
 
P

Pieter Wijnen

the before_update event is even better

Pieter


BruceM said:
The main form's After Update event is a good place to check the various
fields to be sure they contain values. You could hide the tab control,
and make it visible if all of the required fields have been filled in.
Perhaps you could use a "Submit" button or some such thing to save the
record on the main form, and use the form's Before Update event to make
the tab control visible is the required fields have been completed.
In similar fashion you can use the Before Update event of the forms on the
tabs to be sure the required fields have been completed.
Validation code in the form's Before Update event may be something like:

If IsNull(Me.FirstName) Then
MsgBox "You forgot the first name"
Me.txtFirstName.SetFocus
ElseIf IsNull(Me.LastName) Then
MsgBox "You forgot the last name"
Me.txtLastName.SetFocus
End If

This is just one idea. There are lots of ways to go about this. For
instance, you may decide not to hide the tabs. You can still use
validation code. Or you can give the users a chance to bail:

If IsNull(Me.FirstName) Then
If MsgBox ("You forgot the first name." & _
"Click Cancel to exit without saving", vbOKCancel) = vbCancel
Me.Undo
Else
Me.txtFirstName.SetFocus
Cancel = True
End If
ElseIf IsNull(Me.LastName) Then
If MsgBox ("You forgot the first name." & _
"Click Cancel to exit without saving", vbOKCancel) = vbCancel
Me.Undo
Else
Me.txtLastName.SetFocus
Cancel = True
End If
End If

Note that if you decide to hide the tab control you will need code in the
form's Current event to hide the tab control if it is a new record, but
show it for existing records:

If Me.NewRecord Then
Me.TabControlName.Visible = False
Else
Me.TabControlName.Visible = True
End If

If a field is required, you should probably set its Required property to
Yes in table design view. The form's validation code is a convenient (and
potentially user-friendly) way to remind users about required fields that
need values, but is not a substitute for table-level requirements. You
can use table-level validation rules, but it is probably easier for the
user to respond to a form-level error message (in this case, one generated
in the Before Update event).
 
B

BruceM

Oops. Thanks for catching that. I notice that later in the message I
referred to the Before Update event, but for some reason I got the wrong
event the first time I mentioned it. Of course the After Update makes no
sense for validation, since the record has been saved by then.

"Pieter Wijnen"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top