Req. Form Fields/Custom Msgbox

  • Thread starter Thread starter DD
  • Start date Start date
D

DD

My suggestion Table consists of 6 fields. 4 of the fields
are on a user form and the fields are required at the
table level. The other two fields are not required nor are
they contained on the form. If a user does not fill in
field 1 but instead tries to tab to field 2 or click on a
field other than 1 (or does anything other than completing
field 1) and then completing field 2 and 3 and 4
successively, I want to create a message that advises them
field 1 is required and then to set focus back to this
field, or if they complete 1 and 2 and try to bypass 3, an
error message would say that 3 is required and set focus
back to 3. Thanks in advance. You are all so helpful.
 
I would disable the controls for fields 2,3 and 4 and only enable them the
when all the previous data has been entered. This will prevent the users
from doing things in the wrong order, and will mean that the won't get
irritated by messages telling them they've got it wrong!

The easiest way would be to create a function in the form module, and then
set the AfterUpdate event of the controls for fields 1,2 and 3 to the name
of the function. Something like the following should work (untested):

Private Function EnableControls()

With Me
.txtField2.Enabled = Not IsNull(.txtField1)
If .txtField2.Enabled Then
.txtField3.Enabled = Not IsNull(.txtField2)
If .txtField3.Enabled Then
.txtField4.Enabled = Not IsNull(.txtField3)
End If
Else
.txtField3.Enabled = False
.txtField4.Enabled = False
End If
End with

End Function

(That looks more complicated that it should be, but I think it should work!
Obviously, change the names to match the names you have used for the
controls).

Once you've written the function, select the text boxes for the first three
controls, open the property sheet and enter "=EnableControls()" in the
AfterUpdate event. The select the last three text boxes and set the enabled
property to False.

One minor drawback of this is that the controls will not become enabled
until the user either presses the Tab or Enter keys - the will not become
enabled as soon as they type in a character. If this is a problem then you
could probably come up with something using the Change event of the
controls.
 
Back
Top