Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box to make Other Text Fields Visible

Status
Not open for further replies.

sara82

Technical User
May 20, 2005
78
US
I have a combo box, Products, which lists:

BASIC
CHG
CONV
NAT
OS
REV
SP
SS
SUP
TP

I have 5 text fieds which are: BasicThrough, ChgNo, SuppLetter, RevNo, TPNo. The Visible property of all of these text fields is set to No.

If the combo value "Basic" is selected then I want the BasicThrough text fied to become visible and the rest to stay not visible.

If the combo value "CHG" is selected then I want the ChgNo text field to become visible and the rest stay not visible etc.

At first I was going this route:

If Products.value = "BASIC" Then
BasicThrough.visible = true
End if

But that wasn't working.

I tried a select Case


Select Case Product.Value

Case "BASIC"
BasicThrough.Visible = True
ChgNo.Visible = False
SuppLetter.Visible = False
RevNo.Visible = False
TPNo.Visible = False

Case "CHG"
BasicThrough.Visible = False
ChgNo.Visible = True
SuppLetter.Visible = False
RevNo.Visible = False
TPNo.Visible = False
......etc.

End Select

That also didn't work with me. Don't know what I'm doing wrong, and what would be the simplest way of doing it.

Thanks.
 
in the products after update event

BasicThrough.visible = Products.value = "BASIC
ChgNo.Visible = Products.value = "CHG"
SuppLetter.Visible =Products.value = "sup?"
etc..

will test true if it matches the value other wise false

 
Thanks gol4

That worked, but what it is showing is only the text box, the label with the text box doesn't become visible.

Also when I go to the next record and go back to that record it's not retaining that textbox.

For instance Record 1, has BASIC selected, so BasicThrough is shown. I go to Record 2 BasicThrough is still shown even though that is not selected in the combo box. I go back to Record 1 the BasicThrough field is gone.
 
Alright well I have the last part of the task working.

I added that code to the after update event and the on current form event and that retains my values.

Now it's just not making my labels for the fields visible
 
Another thing I encountered. I wanted the SuppLetter field to appear with either of the 3 values: OS, SS, or SUP.

I went ahead and gave this a shot but got a debug error:

SuppLetter.Visible = Product.Value = "OS" Or "SS" Or "SUP"

Any suggestions.
 
SuppLetter.Visible = (Product.Value = "OS" Or Product.Value = "SS" Or Product.Value = "SUP")
And if the labels are attached to the controls:
For Each ctrl In SuppLetter.Controls
ctrl.Visible = SuppLetter.Visible
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for your help, everything is good.

I appreciate it.
 
I have the following code for frmWorkLog

Code:
Option Compare Database

Private Sub toggleprop()
' Sub procedure that toggles the visible properties of the text fields
' depending on what value of the combobox, Product, is selected

BasicThrough.Visible = Product.Value = "BASIC"
ChgNo.Visible = Product.Value = "CHG"
RevNo.Visible = Product.Value = "REV"
SuppLetter.Visible = (Product.Value = "OS" Or Product.Value = "SS" Or Product.Value = "SUP")
TPNo.Visible = Product.Value = "TP"

End Sub

Private Sub Form_Current()
'Calls the subprocedure and retains the value of property if it is not a new record

If Not Me.NewRecord Then
  Call toggleprop
End If

End Sub

Private Sub Product_AfterUpdate()
'Calls the subprocedure in the afterupdate event of the Product combo box

Call toggleprop
     
End Sub

In my form when I go to a new record, if the previous record selection is BASIC in the combo box so that the BasicThrough text field appeared, when I go to a new record the BasicThrough text field is still there. How can I make it that it's not?
 
Simply get rid of the test about new record in the Current event procedure.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
When I got rid of

If Not Me.NewRecord Then
Call toggleprop
End If

It still didn't update, that field is still there.

 
What I suggested:
Private Sub Form_Current()
Call toggleprop
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
When I did that, I got an error message:

Run-time Error 94
Invaild use of Null

So what I did was

Code:
Private Sub Form_Current()


BasicThrough.Visible = False
ChgNo.Visible = False
RevNo.Visible = False
SuppLetter.Visible = False
TPNo.Visible = PFalse

If Not Me.NewRecord Then
  Call toggleprop
End If

End Sub

That seems to work..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top