Lock fields based on another field value

G

Guest

I have setup radio buttons at the top of my form. Based on which value is
selected I would like to lock fields within the rest of the form. For
example, student is one option within the radio buttons and faculy is
another. If student (value equals 1) is selected I want the faculty id
number within the same form locked because a student does not have a faculty
id. Is this possible or am I going to have to build numerous forms and
subforms????
 
B

Bob Howard

Not knowing how many radio buttons you have, I would do this by creating two
subs in the VBA code --- one for Student Setup and one for Faculty Setup.

Private Sub StudentSetup()
On Error Resume Next
' Put these for each control to be locked for a Student
Me!controlname1.Enabled = False
Me!controlname1 = "" ' to clear out any data already entered
....
etc.
....
' Put this for each control to be unlocked
Me!controlname9.Enabled = True
....
etc.
....
End Sub

Similar for FacultySetup.

Then, set up an OnClick event for each button --- if that button applies to
a student, use something like:

Private Sub radiobutton1-Click()
StudentSetup
End Sub

If it applies to faculty, use something like:

Private Sub radiobutton14-Click()
FacultySetup
End Sub

You should lock / unlock every control in each of the StudentSetup and
FacultySetup subroutines so the user can change his/her mind before or after
starting to enter the data. When all the data is entered to their
satisfaction, they should have some button to press where you would act on
what was entered.

I'm a simple-type coder --- this may not the most efficient but it's the
simplest for me to visualize.

Bob.
 
G

Guest

The functionality of what you want to do is possible but I would question the
reason that you want to do it. If you're trying to use one form for all of
your data entry...making it generic...then I think you're going to run into
problems. Not knowing the specific reasons however I would say to add code to
the AfterUpdate event of the option group).

Private Sub OptYourOptionGroup_AfterUpdate()
If Me.OptYourOptionGroup.Value = 1 Then
Me.YourFacultyControlName.Enabled = False

You'd have to apply this same code to the OnCurrent event of the form.
 
G

Guest

Thank you, I will try. The form is all basic information name, address, etc.
for each person. There is just one field I only want input if the person is
marked student. I had original planned to make a separate forms for all but
quickly came to realize there was just one field different. I want to lock
it because I know the person who will do the data entry is bound to put
garbage information if I leave the field open.

Did you have other recommendations?? I am new to access and would love any
suggestions.
 
G

Guest

I have to disagree with this approach. Since both situations use the same
data from the same table, duplicating a form with minor changes has some
drawbacks.
First, any future changes mean you have to do the same work twice.
Second, If you discover a bug, you have to fix it twice.
and Third, Adding an additional form and it's code increases database size.
 

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

Top