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

Make label visible if

Status
Not open for further replies.

hayde

Technical User
Feb 16, 2005
10
0
0
US
I am having a hard time trying to make a label visible only if there is a certain entry in a combo box. what I have been working with is the following

If Me.Insurance = "Medicare" Then
Me.Label262.Visible = True
Else
Me.Label262.Visible = False

End If

I have put this in the current and after update events but it just won't work. Am I missing some crucial part of the code or are there any suggestions of a different route to try.
 
Try this:


If Me!Insurance = "Medicare" Then
Me!Label262.Visible = True
Else
Me!Label262.Visible = False

End If


or this

If Insurance = "Medicare" Then
Label262.Visible = True
Else
Label262.Visible = False

End If

 
Hi, hayde,

The current and after update events of which object? The form or the combo? (there is no current event of a combo) Try the AfterUpdate event of the combo. Another thing to look for - what is the bound value of the combo?

Ken S.
 
Hi!

As far as I can tell the code looks okay assuming you put it in the afterupdate event of the insurance text box and in the current event of the form.

Another possible method would be to use the conditional formatting in the format menu. Click on the label and then choose Format-Conditional Formatting. Under Condition 1 click on the arrow in the drop down box and choose Expression is. Then it the box that will appear type:

Me!Insurance <> "Medicare"

Then choose to make the label invisible.

hth
P.S. I'm not sure that conditional formatting works with labels since I have never tried it.

Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
I've tried the all the above suggestions but still no luck. I have put the event in the current of the form and also the afterupdate of the combobox. I'm not sure what I should be looking for regarding the bound value of the combo. I played around with it but apparently having hit upon the right combination yet. Conditional formatting sounded great but I don't have that option for labels. I really appreciate the suggestions. Send more thoughts my way please.
 
Use debug to see what your code is doing. To use debug, place the cursor on the line that says If (me!Insurance <> "Medicare") and press F9 (sets a breakpoint). (Or place the word stop above the line.) Then execute your code. Your program will pause execution when it encounters the breakpoint (or stop). At that point, you can use the Immediate Debug window to examine variables (?Insurance.value) and step thru your code one line at a time by pressing F8. Hold the cursor over a variable and the value of the variable will be shown. Press F5 to continue execution of your code until it encounters the next breakpoint, stop, or exits
 
How many columns in your combo box? My guess is that you have 2 columns, with the first one being zero length. That would be your bound column and probably has a numerical value. If I'm right, you have a couple of options....

1. If Me.Insurance = 1 Then
2. If Me.Insurance.Column(1) = "Medicare" Then

Remember that combo box columns start counting at 0.




Randy
 
That didn't work either. I'm going to give up for the day and maybe tomorrow I find some stupid mistake I made. Thanks for trying to help.
 
Have you tried FancyPrairie's suggestion to determine the value of your combo box?

Randy
 
Hayde,
Here is some code that is working for me in a similar fashion. I had a lot of trouble with field [Paid] not being updateable to start with, so perhaps that is the source of your trouble. But the check on it's status before changing it seemed to solve that issue.
Code:
Private Sub Form_Current()
Me!frmOrderSubDetail!ProductID.Requery
Me!txtAmtLeft.Visible = False
Me!lblPartPaid.Visible = False
Me!Paid.Visible = True
If IsNull(Me!txtSoP) Or Me!txtSoP = 0 Then
    If Me!Paid = True Then Me!Paid = False
    Me!lblPaid.BackColor = 255
End If
If Me!txtSoP = Me.frmOrderSubCost.Form!OrderTotal Then
    If Me!Paid = False Then Me!Paid = True
    Me!lblPaid.BackColor = 16777215
End If
If Me!txtSoP > 0 And Me!txtSoP < Me.frmOrderSubCost.Form!OrderTotal Then
    Me!txtAmtLeft.Visible = True
    Me!lblPartPaid.Visible = True
    Me!Paid.Visible = False
    Me!txtAmtLeft = Me.frmOrderSubCost.Form!OrderTotal - txtSoP
End If
Refresh
End Sub
Hope this helps,
Phil
 
I finally got back to working on this. Thanks everyone. I hadn't know how to use debug before. Once I figured that out my problem was solved by using the following code:

If Me.Insurance.Column(2) = "Medicare" Then

Thanks so much for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top