Visible/Hidden Fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to have a field displayed based on what is selected from a combo
box in another field. Here is what I have so far.

I have a combo box named Phase. In that combo box is two choices, Planning
and Completed.

I have two other fields that I would like to be hidden until a certain
choice is made. One field is named txtFifty and one is named txtHundred. When
Planning is selected from the combo box I want the field txtFifty to be
visible. And the same for Completed and the field txtHundred.

Here is what I have in my code. On the combo box On Click Event I have coded

Private Sub Phase_OnClick()
If Me.Current_Phase = "Planning" Then
Me.txtFifty.Visible = True
Else
Me.txtFifty.Visible = False
End If

If Me.Current_Phase = "Completed" Then
Me.txtHundred.Visible = True
Else
Me.txtHundred.Visible = False
End If
End Sub

My question is how can I have the field displayed permanently based on what
is selected in the combo box. For example if Planning is selected in the
combo box, I want the text field Fifty to be displayed for good whether a
user types in a value or not.

Hopefully I explained it well enough. Thank you for your help in advance.

Peace,

Saj
 
First you can make your code shorter

Private Sub Phase_OnClick()
Me.txtFifty.Visible = (Me.Current_Phase = "Planning")
Me.txtHundred.Visible = (Me.Current_Phase = "Completed")
End Sub

For your question, if I understood your question, call the OnClick sun from
the OnCurrent event of the form

Call Phase_OnClick
 
saj2004 said:
I am trying to have a field displayed based on what is selected from a combo
box in another field. Here is what I have so far.

I have a combo box named Phase. In that combo box is two choices, Planning
and Completed.

I have two other fields that I would like to be hidden until a certain
choice is made. One field is named txtFifty and one is named txtHundred. When
Planning is selected from the combo box I want the field txtFifty to be
visible. And the same for Completed and the field txtHundred.

Here is what I have in my code. On the combo box On Click Event I have coded

Private Sub Phase_OnClick()
If Me.Current_Phase = "Planning" Then
Me.txtFifty.Visible = True
Else
Me.txtFifty.Visible = False
End If

If Me.Current_Phase = "Completed" Then
Me.txtHundred.Visible = True
Else
Me.txtHundred.Visible = False
End If
End Sub

My question is how can I have the field displayed permanently based on what
is selected in the combo box. For example if Planning is selected in the
combo box, I want the text field Fifty to be displayed for good whether a
user types in a value or not.


Execute the same code in the form's Current event.

That will raise the question of what you want to happen when
you navigate to a new record where the combo box's value has
not been set (same question on existing records when users
forget to enter all the data).

Select Case Me.Current_Phase
Case "Planning"
Me.txtFifty.Visible = True
Me.txtHundred.Visible = False
Case "Completed"
Me.txtFifty.Visible = False
Me.txtHundred.Visible = True
Case Else
Me.txtFifty.Visible = False
Me.txtHundred.Visible = False
End Select

I also recommend that you use the combo box's AfterUpdate
event instead of the Click event, Even if it's harmless,
the click event may be triggered even when the value has not
been changed.
 

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

Back
Top