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

Programmatically change label caption on form 4

Status
Not open for further replies.

jjlogan

Programmer
Joined
Jan 11, 2002
Messages
178
Location
US
This should be easy, but not working. I've set up a form in Access 2003 which includes a label to give information associated with each record, e.g. the records fall into three categories and let the User know which category: if category A, then I make the label visible and want to show the caption statement; if category B, then again show the label but with different caption; if category C, make the label invisible because C is the normal category.

My code first checks the Category Code with a Select Case block; within this block I try to change the caption as follows:
Me!lblName.Caption = "Warning - this is Category A"
Me!lblName.visible = True

My code works fine in turning on and off the visible property, but the label always appear blank when visible is True.
Please help. I've read FAQ's, Google, MS Help, and searched threads. Even MS helps does not address changing the caption text of a label (it only shows back/fore color and border property changes). Thanks for any help.
Jeff
 
Perhaps you should make the label visible BEFORE changing its caption ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV - I changed the code to set the visible property of the label to True BEFORE setting the caption and it still is not showing a caption (label border has always been partly visible along top and right sides I believe). I've also looked at my font colors and have black set as the forecolor; label shows visible with white background).
Jeff
 
PHV -
A thought came to me - that I could overlay labels with the different caption messages and then just management in code their visible property. This way I avoid the caption text change with each new current record.
Jeff
 
jlogan,

Can you post the entire select case statement?
You should have no difficulty changing the caption with the code you've shown here.


Randy
 
Randy,
Here is the snippet of code from my Form_Current Sub Procedure:

If Not IsNull(Me!GOCO_ALLOCATED) Then
Select Case ALLOC_CODE
Case "YB"
With Me!lblGOCO
.Caption = "Job cost is allocated only to GOCO's X and Y. If cost is for these GOCO's, no adjust necessary unless FAR unallowable."
.Height = 0.5208
End With
Case "HB"
With Me!lblGOCO
.Caption = "Job cost is allocated only to GOCO's Y and Z. If cost is for these GOCO's, no adjust necessary unless FAR unallowable."
.Height = 0.5208
End With
Case Else
With Me!lblGOCO
.Caption = "Job cost is allocated to all GOCO's. No adjust necessary unless FAR unallowable."
.Height = 0.3333
End With
End Select
Me!lblGOCO.Visible = True
Me!cmdGOCOInfo.Visible = True
Else
Me!lblGOCO.Visible = False
Me!cmdGOCOInfo.Visible = False
End If

Jeff
 
I think it is setting the Height property that is doing you in. The height that you see on the properties when in design mode is not the same scale as inside the running code.

For example, when I have the form in design mode the Height is "0.46cm". But in the following code:
Code:
Private Sub txtCode_DblClick(Cancel As Integer)
    MsgBox "My height = " & txtCode.Height
End Sub
I am told the height is 230.

Setting the height to 0.5208 in you code is probably making it too thin to be seen.

 
G'day JoeAtWork

You're correct. Height and width have to be set in pixels - stupid, huh?

FWIW, 1cm = 567 pixels, 1inch = 1440 pixels.

jjlogan, I'd suggest you create a global const to use in other modules, eg
Public Const PIXELSPERCM% = 567

Then, your code can use it like this:

.Height = 0.3333 * PIXELSPERCM

Max Hugen
Australia
 
The unit of measure is called [blue]twips![/blue]
1" = 1440 twips . . .

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

Be sure to see FAQ219-2884:
 
Thank you all (Randy, Joe, Max, and Ace) for the tips - the problem is solved. Sure enough, the label control was displaying only the top border due to height being so small. I did use the global constant as a factor to adjust height.
Thanks much,
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top