Conditional Text Box

J

JDB

One box in my form is a drop down list combo box. Depending on what is
selcted in the box, I'd like other text boxes on the form to be locked or
open.

For example, if the user selects 'Coach' in the combo box, I want them to
enter the coach's address. If they select 'Player" I do not want them to
have the ability to enter address info.

Thanks in advance for your help.
 
A

andrew

in the AfterUpdate event for the combo, something like this should do the
trick:

If Me.ComboBoxName.Value = "Coach" Then
Me.CoachAddressBox.Locked = False

Else
Me.CoachAddressBox.Locked = True

End If


Andrew
 
J

John W. Vinson

in the AfterUpdate event for the combo, something like this should do the
trick:

If Me.ComboBoxName.Value = "Coach" Then
Me.CoachAddressBox.Locked = False

Else
Me.CoachAddressBox.Locked = True

End If

You can also set the address textbox's Enabled event (to True or False
respectively, opposite the choices for Locked); this has the advantage that
the control is visibly "greyed out" so the user doesn't try to type in it and
get frustrated when it doesn't work.
 
J

JDB

Thanks Andrew. I'm sure this is easy, but I am not a heavy Access user and
am not getting it.

I tried your code in Code Builder and it didn't work. I also tried this,
based on an example in VB Help -

Private Sub SiteContactTitle_AfterUpdate()
' Enable controls if SiteContactTitle is Primary Coach.
If Me.SiteContactTitle = "Primary Coach" Then
Me.SiteGrades.Enabled = True
Me.SiteGrades.Locked = False
Else
Me.SiteGrades.Locked = True
End If
End Sub

Which also didn't work. Any ideas? Also, is there something concrete that
needs to be done on AfterUpdate to get this code to run? I assume not, but
am trying to cover all the bases on why i can't get something simple to work.
thanks again. JDB
 
A

andrew

OK.

Firstly, I think John's suggestion of enabling / disabling the box is better
than my suggestion of locking it.

Secondly, your code enables and unlocks the box if the condition is true,
but only locks it otherwise. I think enabling / disabling the box would be
sufficient. It may be that the data is still dirty - i.e. it has not yet
been committed to the table. I would have thought this should work - I
haven't tested it specifically, but I do use something similar myself and it
seems to work OK:

Private Sub SiteContactTitle_AfterUpdate()
' Enable controls if SiteContactTitle is Primary Coach.

' flush data to table
Me.Dirty = False

If Me.SiteContactTitle = "Primary Coach" Then
Me.SiteGrades.Enabled = True
Else
Me.SiteGrades.Enabled = False
End If
End Sub
 
J

JDB

I really appreciate all the help. Obviously, I am feeling my way through
this, so your guidance is appreciated.

Here is what i put in the On AfterUpdate event:

Private Sub SiteContactTitle_AfterUpdate()
' Enable controls if SiteContactTitle is Primary Coach.
' flush data to table
Me.Dirty = False

If Me.SiteContactTitle = "Primary Coach" Then
Me.SiteGrades.Enabled = True
Else
Me.SiteGrades.Enabled = False
End If

I am still doing something wrong, but it doesn't work.

I tried both modifying an existing record int he form, and entering a new
record and the SiteGrade box is enabled throughout. The only time i could
get is disabled is if I disable it in its properties (which the preferred
default state, enabled only if Primary Coach is selected).

A couple thoughts -

The SiteContactTitle is a combo box Value List with the Row Source showing
the options (primary coach, coach, etc.)....could this be the problem?

Also, SiteContactTitle is the Control Source, I assume that is the correct
thing to use, and not the Name of the combo box...correct?

Finally, do I just save and close the VB code editor, or is there something
else i need to do in order for any changed to be made.

Thanks again.

Joe
 

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