Consulting

Results 1 to 4 of 4

Thread: SOLVED: Uncooperative label control properties

  1. #1
    VBAX Contributor
    Joined
    Jun 2004
    Location
    Texas
    Posts
    139
    Location

    Unhappy SOLVED: Uncooperative label control properties

    Hi,

    I am working on a piece of code which, based on the user's selection, loops through all the db forms and changes several properties of all label controls. Among other things, I want the code to change the labels' bg color based on user selection, but I never want the labels' bg style to be transparent.

    I started with all labels set to normal, and the default control style is normal. My code specifically sets it to normal as well. After the code runs, the default control style is set to normal, but EVERY LABEL has reverted to transparent. I cannot figure out why they are doing this!! I am confused and frustrated.

    Please help if you can. I have posted the most relevant chunk of my code below, dunno if it will help or not, please ask if more info would help you help me!! Suggestions are deeply appreciated. Thank you so much!!!

    [vba]
    For Each doc In ctr.Documents
    DoCmd.OpenForm doc.Name, acDesign, , , , acHidden
    Set frm = Forms(0)
    If frm.Tag = "BGNrml_TextNrml" Then
    With frm
    .Section(acDetail).BackColor = 16764057
    .Section(acPageHeader).BackColor = 16764057
    .Section(acPageFooter).BackColor = 16764057
    .Section(acHeader).BackColor = 16764057
    .Section(acFooter).BackColor = 16764057
    End With
    End If
    For Each ctl In frm.Controls
    If ctl.Tag = "BGNrml_TextNrml" Then
    ctl.BackStyle = Normal
    ctl.BackColor = 16764057
    ctl.ForeColor = 0
    ElseIf ctl.Tag = "BGNrml_TextHighlight" Then
    ctl.BackStyle = Normal
    ctl.BackColor = 16764057
    ctl.ForeColor = 16711680
    ElseIf ctl.Tag = "BGHighlight_TextDrk" Then
    ctl.BackStyle = Normal
    ctl.BackColor = 16776960
    ctl.ForeColor = 0
    ElseIf ctl.Tag = "LineNrml" Then
    ctl.BorderColor = 0
    ElseIf ctl.Tag = "LineHighlight" Then
    ctl.BorderColor = 16711680
    End If
    Next ctl
    DoCmd.close acForm, doc.Name, acSaveYes
    Next doc
    [/vba]
    Last edited by mark007; 06-30-2004 at 06:12 AM. Reason: Check out the VBA tags for formatting code!;)

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi eed,

    The BackStyle Property takes a numeric value (0=Transparent and 1=Normal). You are setting it to a variable, Normal. Assuming you don't have it declared, and are not using "Opton Explicit", Normal will default to a value of 0 (i.e. transparent).

    To make it work, use

    [VBA]ctl.BackStyle = 1[/VBA]

    To make it slightly easier to understand, define and use some contants. At the top of your module add ..

    [VBA]
    Enum myBackStyles
    myTransparent
    myNormal
    End Enum
    [/VBA]

    .. and then use

    [VBA]ctl.BackStyle = myNormal[/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    VBAX Contributor
    Joined
    Jun 2004
    Location
    Texas
    Posts
    139
    Location
    Thanks Tony, I appreciate the reply, but the procedure still doesn't run correctly.


    I had my bg style set to numerics first, then decided to try text settings (normal/transparent) based on something I saw in a help file, but neither works. Even when I set it to 1, all the labels decide to become transparent instead.
    Any more ideas as to what might be going wrong here? I've been testing, tweaking, and retesting for a week, and I know I must be overlooking something but I can't fathom what. Thanks to all who read, and thanks in advance for any further replies!!
    With program specs this fickle, you've just got to believe in Discord.

  4. #4
    VBAX Contributor
    Joined
    Jun 2004
    Location
    Texas
    Posts
    139
    Location
    Okay, well, it didn't like the numeric setting, but it actually DID like your Enum "myNormal" idea. Now the labels are working. I've still got to sort out some other issues, but at least I don't have to agonize over this one anymore. Thanks, Tony!!!
    With program specs this fickle, you've just got to believe in Discord.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •