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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change visability status based on pull down

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
523
US
Hi all,

This is a easy question I think, but for the life of me I can't remember how to do these two operations.

The first is to make a second fields visability dependant on a previous field. IE: Pull down has Apple Orange and Blueberry. If Orange is selected field 2 becomes visable.

I know that this also can be done with a subform, but if pull down one is a list from a table, I get an error saying that the data types are not the same. Can someone please help me out? Thanks.
 
A starting point.
In the Current event procedure of the form and the AfterUpdate event procedure of the [pull down] control:
Me![field 2].Visible = (Me![pull down] = "Orange")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
In the afterupdate event of the combo, something like:

If Me.combobox = "Orange" then
Me.SecondField.visible = true
else
Me.SecondField.visible = false
end If


Pampers [afro]
Keeping it simple can be complicated
 
Just to double check, replace we with the form name or is it the table name?
 
Ok so here are the two different field names:

Location
Testing Station

So I tried both methods and when Location = "other" the Testing station field goes away as it is supposed to, but when Location = "Testing Station", the Forms Field Testing Station does not appear. Any ideas what could be wrong? I like the code:

If Me.[Location] = "Testing Station" then
Me.[Testing Station].visible = true

else

Me.[Testing Station].visible = false

end If

Is there anything wrong with this code?

Thanks again!
 
Hi remeng,
Just to be sure, we are now only showing/hiding a field (textbox) in a form, right? There are two controls on the form:
1. Location (which is a combobox);
2. Testing Station (which is a textbox).

First of all, the names of the controles are not very well choosen (as you can see, it is confusing). Rename your controls as follow:
1. cboLocation (so everyone knows it is a combo)
2. txtTestingLocation (so everyone knows it is a textbox- don't use spaces in control names

Also, post your code including the beginning and end of the procedure.

The code as far is I can see is ok, but the string-comparison has to be precise. So check that.


Pampers [afro]
Keeping it simple can be complicated
 
Both are text fields (no check boxes).

Location (pull menu with "Testing Station" as an option)
Testing Station (field with different stations as options)

I attemped to rename the testing station field as teststa:

Private Sub Location_AfterUpdate()

If Me.[Location] = "Testing Station" Then
Me.[teststa].Visible = True

Else

Me.[teststa].Visible = False

End If

End Sub

I had no luck, so I place teststa as invisable to start and the field would not reappear. I still have the same problem. I am thinking of remaking the field so that there might not be background problems. Any suggestions before I do this?

 
OK, so I have now tried re-typing the code, and am now receiving an error, Else statement without If. Here is the code.

If Me.Location = "Testing Station" Then Me.teststa.Visible = True

Else: Me.teststa.Visible = False

End If

End Sub
 
Check your code if you see an error like this: Looks like their is something wrong with the IF-part of the IF-THEN-ELSE statement. Also post the whole code, including Procedure Sub untill End Sub.

Furthermore, you wrote in the first mail:
The first is to make a second fields visability dependant on a previous field. IE: Pull down
. What happened to the PullDown (Combobox).

I'm not talking about checkboxes but comboboxes



Pampers [afro]
Keeping it simple can be complicated
 
based on what I have posted can you recreate the proper code using my fields? I don't know where I went wrong. Thanks.
 
Code:
If Me.Location = "Testing Station" Then 
   Me.teststa.Visible = True
Else 
   Me.teststa.Visible = False
End If


Pampers [afro]
Keeping it simple can be complicated
 
tried and failed again, no error, just did not show the field. Could there be something that I am missing? The names are all correct. I have checked 4 or 5 times times. Instead of me should I use the form name?
 
Hi remeng,
I think I asked before, are we hiding/unhiding fields or forms?

For subforms you need indeed a different reference.

Me.frmMyFormName.Visible = true

Make it a habit to give your control proper names. For forms use the prefix frm.

Pampers [afro]
Keeping it simple can be complicated
 
How are ya remeng . . .

If by [blue]PullDown[/blue] you mean a [blue]combobox[/blue], then in the forms [blue]On Current[/blue] event, try"
Code:
[blue]If Me.[purple][b][i]ComboboxName[/i][/b][/purple].Column(?) = "Orange" then
   Me.[purple][b][i]SecondField[/i][/b][/purple].visible = true
Else
   Me.[purple][b][i]SecondField[/i][/b][/purple].visible = false
end If[/blue]
This is simply an extension as far as referencing the combobox in [blue]Pampers's[/blue] code is concerned!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
What happens when you add the red line in your code ?
Code:
If Me!Location = "Testing Station" Then 
   Me!teststa.Visible = True
Else 
   Me!teststa.Visible = False
   [!]MsgBox "Location='" & Me!Location & "'"[/!]
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Sorry I haven't been back in a while, had other work to do so I couldn't play around. I attempted your script change and I received three different errors. The first was when the selection is In Storage Slot (The first value):

Location='1'

The second was when I select Testing Station (the third value):

Location='3'

the third error is when I select Signed Out (the second value)

Location='2'

These values are dirrect result of the order that they are in the table.
 
Ok so I was playing and I think I made some headway. I changed the code to this and the Testing Station field acted properly, but with a small side problem, when I select something other than Testing station I still get errors for Location='1' and Location='2'.

If Me!Location = "3" Then
Me!teststa.Visible = True
Else
Me!teststa.Visible = False
MsgBox "Location='" & Me!Location & "'"
End If

Additionally the label for the field did not appear.

Thanks all for the continues help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top