Restrict the user to fill a field on a form

emsadoon

Registered User.
Local time
Today, 05:50
Joined
Jun 6, 2013
Messages
83
I have two fields on a form. One of the fields has to be entered first in order for the other field to be filled. How can I restrict the user to enter a value in filed #2 before filling the filed #1?
 
in the form current event put the following - change names to suit

fld2.enabled=fld1<>"" 'or 0 if numeric

and in the after update event of fld1 put the same code
 
This is very easy, by hide, lock or disable the control for Field2.
The main question is: How to check when the control for Field1 is filled ?
Say that a user must fill the Field1 with a numeric data.
After he type "1" is OK because is a numeric data. But, maybe, the input should be at least "123".

So, using pseudo code, your approach should be:
Code:
Private Sub ControlForField1_Change
   If Field1_IsFilledWithRightData then
     ControlForField2.Locked = False
   Else
     ControlForField2.Locked = True
   End if
End Sub
 
in the form current event put the following - change names to suit

fld2.enabled=fld1<>"" 'or 0 if numeric

and in the after update event of fld1 put the same code


I implemented the above code, but it did not work. I guess it is just because my field#1 is a check box. Here is the code that I have :

Private Sub Form_Current()
ProjectApprovalDate.Enabled = ProjectApproved <> ""
End Sub

Private Sub ProjectApproved_AfterUpdate()
ProjectApprovalDate.Enabled = ProjectApproved <> ""
End Sub
 
It sounds like ProjectApproved defaults to false so change to

Private Sub Form_Current()
ProjectApprovalDate.Enabled = ProjectApproved
End Sub

Private Sub ProjectApproved_AfterUpdate()
ProjectApprovalDate.Enabled = ProjectApproved
End Sub
 
It sounds like ProjectApproved defaults to false so change to

Private Sub Form_Current()
ProjectApprovalDate.Enabled = ProjectApproved
End Sub

Private Sub ProjectApproved_AfterUpdate()
ProjectApprovalDate.Enabled = ProjectApproved
End Sub


Can I also make [ProjectApprovalDate] required to be filled, once the ProjectApproved filled?
 
Yes

in the form beforeupdate event put code something like this (not tested)

Code:
if [ProjectApproval]=true and nz([ProjectApprovalDate])="" then
    msgbox "you must enter an approval date"
    projectapprovaldate.setfocus
    cancel=true
end if

What you actually need depends on how your form is intended to work - are there other fields that must be completed etc. Validation around the date entry (i.e. must be later than today and within 3 months, etc)
 

Users who are viewing this thread

Back
Top Bottom