Set visible by keyword

wop0703

Registered User.
Local time
Today, 16:55
Joined
Jun 1, 2005
Messages
77
In my form, I have a combo box with one of three options (cash, check, reimbursement). If the user chooses check, I want a text box to become visible, so the user may input the check number.

I thought I could use another invisible text box to store the value of the combo box and then in the code put:

Private Sub Text64_AfterUpdate()
If Text64 = "Check" Then
Me.Check1.Visible = True
Else
Me.Check1.Visible = Refresh
End If
Me.Refresh
End Sub

Text64 is holding the value of the combo box
Check1 is the text box where I want the user to put the check number.

Please help. Thanks
 
Set the visible value of Check1 = no

If Me.YourComboName = check Then
Me.Check1.Visible = True
Else: Me.Check1.Visible = False
End If
Me.Refresh
 
I put the code in the after update of my combo box and nothing happened. Do I need to put it somewhere else?
 
No, that's where it should be
Make sure the names are correct and it should work fine
 
For some reason, it is not working. It doesn't make much sense to me. Here is my exact code:

Private Sub Type1_AfterUpdate()
If Me.Type1 = Check Then
Me.Check1.Visible = True
Else: Me.Check1.Visible = False
End If
Me.Refresh

End Sub

Type1 is my combo box
Check1 is my text boxI want visible
 
Sorry, my mistake
It needs "" so try this:

If Me.Type1 = "Check" Then
Me.Check1.Visible = True
Else: Me.Check1.Visible = False
End If
Me.Refresh


If you were using a numerical value "" around the value of Me.Type1 would not be needed

EG
If Me.Type1 = 12 Then
 
Last edited:
You may also need the same code on the ON CURRENT event of the form, so that when you switch between records the check number is appropriately displayed.

I also do not think you need "me.Refresh" but I could be mistaken.
 
ejstefl said:
I also do not think you need "me.Refresh" but I could be mistaken.

I just tried it and it works without the me.refresh....
Thanks for pointing that out!
 
OK, another visibility question. The same form's information is placed in a table. It takes 3 pieces of information from that table. One piece of the information is a year field (has either freshman, sophomore, junior, or senior). I want a text box to appear when the field has freshman in the field. I tried to use the same cod and swich the variable names but it did not work. Any suggestions?
 
Did you set the visible property of your text box to no?
 
Yes I did. I have the value of Freshman in a text box that is not enabled, is this ok?
 
I just tried this and it works if txtbox is either enabled or not enabled

If Me.txtbox = "freshman" Then
Me.txtbox2.Visible = True
Else: Me.txtbox2.Visible = False
End If


txtbox2 has to be set to visible = no
 
Just as an aside, are you acutally storing the words "Freshman," "Sophomore," etc. in that field? Generally, when you a field like that that can only be 4 values, you'd want to create a table with two fields:

tblYear
YearID - pk
YearDescription

Then, you would store the YearID in your main table as a foregin key. You can use a combo box to enter data to the field.

This cuts down space used in your database, cuts down data entry errors, and makes comparisons much easier since you don't have to worry about quotes (you'll be comparing numebrs). If you ever get into using SQL and VBA, you'll realize how much easier it is to deal with numbers than text.
 
This doesn't have the PK - FK setup but you may find this interesting...... see attachment
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom