Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change backcolor of label on access form and make checkboxes visible

Posted on 2014-09-08
13
Medium Priority
?
521 Views
Last Modified: 2014-09-09
I have a bunch of labels on my form that when a user clicks on one of them I need the backcolor of that label to change to yellow. And then if they double-click on it then it changes back to the standard white color. Is there a function that I can call from the "On Click" and "On Dbl Click" events instead of typing an IF statement for each label? I would prefer to just have a function to run these two pieces of code so I can call the code with line of code instead of an IF statement for each label. I know I've seen something like this before.

The second part of this might not be doable...With each of these labels I have 2 checkboxes (not associated with this label). When the user clicks on the label I want it to change the backcolor as outlined above, but then I need to have these 2 checkboxes to be visible (they aren't visible as the default setting). Then if they double-click on the label then these two checkboxes will be unchecked (if they were checked) and then have them disappear and no longer be visible. When they are not visible they should never be checked. They can only be checked if the user clicks on the label to make them appear. Then the user can check them if needed. But then if they double-click on the label both checkboxes are unchecked and then disappear. Like I said, not sure if this part is doable.

Just trying to simplify this code and not have a bunch of IF statements for each labels click & double-click events.
0
Comment
Question by:Lawrence Salvucci
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 9

Expert Comment

by:macarrillo1
ID: 40311009
For the first one; I would use the Form Events (on click and on Double Click).
Then you could use the tag property of each of the labels and set them to a specific value (like 'Color me'). Then loop through all the controls on the form and apply the color change.

The Check boxes can be done.  But setting the event on the form might not be good after all if you need to do both.

You might need to put your labels inside some kind of container and then use the containers event properties.

Check boxes can make use of the tag field as well. Perhaps sets its value to 'Check me' and include in loop.  

I think my concern is a single click can trigger the whole thing.  You want to carefully consider what is clicked to do this.
You could use a button or put a picture (icon) on the form that users click, instead of just any label.
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 40311021
So if I use the On Click and Double-Click of the forms events then how do I write the code to have it change the color for a specific label when it's clicked or double-clicked?

What do you mean put the labels in a container? Not sure I follow you there.

A single click on a specific label will turn on (make visible) the 2 checkboxes that go with that label (although not associated) and also change the backcolor of that label to vbYellow. And a double-click will make them have false values and make them not visible. But it will also change the backcolor of that label to vbWhite.

I would prefer to find a way to do all this from the specific label instead of a button since not every label will change the backcolor. Only the label that is clicked on.
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 40311046
So doing a little more research on this. I found this code that does what I want as far as changing the backcolor of the label when you click and double-click it. But it does it for all the labels on my form, not just the one I click on. How can this be modified to only change the backcolor of the label I actually click or double-click?

Private Sub Form_Open(Cancel As Integer)
       For Each ctrl In Me.Controls
        If ctrl.ControlType = acLabel Then
            ctrl.BackColor = 13754083
            End If
        Next ctrl
End Sub

Sub Enter_Option()
    OptionNameStr = Me.ActiveControl.Properties("name")
    For Each ctrl In Me.Controls
       If ctrl.ControlType = acLabel Then
               LabelNameStr = ctrl.Properties("name")
               ctrl.BackColor = vbYellow
           End If
        Next ctrl
End Sub

Sub Exit_Option()
    OptionNameStr = Me.ActiveControl.Properties("name")
    For Each ctrl In Me.Controls
       If ctrl.ControlType = acLabel Then
               LabelNameStr = ctrl.Properties("name")
               ctrl.BackColor = 13754083
           End If
        Next ctrl
End Sub

Private Sub lblExcellenceSub1_Click()
Call Enter_Option
End Sub

Private Sub lblExcellenceSub1_DblClick(Cancel As Integer)
Call Exit_Option
End Sub

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:macarrillo1
ID: 40311233
Ok, It looks like I misunderstood what you were trying to do. So to make sure I understand:

CheckBox1
CheckBox2

Label1
Label2
Label3
Label4
Label5

If any label (1-5) is clicked it should turn colors and checkboxes are visible
If no labels are colored then Checkboxes are unchecked and not visible.

If this is correct then:

Each label has on click event to turn on color background and set Property Tag to 'Color' for label.
Each label has on double click  event to turn off color and set Property Tag to 'No Color' for label.
Default value for Property Tag is 'No Color' for each label.

On form Click event:
Loop through all controls with Tag values.

If count of TagsHaveColor > 0 then
CheckBox1 and CheckBox2 are visible.
Else
CheckBox1 unchecked
CheckBox2 unchecked
CheckBox1 and CheckBox2 hidden.

Does this describe what you are trying to do?
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 40311691
Yes it does, but not completely. Each label has it's own 2 checkboxes. So if I have 5 labels on my form then I have 10 checkboxes. Each label has 2 checkboxes that are made visible when the label is clicked and then invisible when the label is double-clicked. And along with that when the label is clicked once the backcolor of the label will turn to vbYellow. And when it's double-clicked it turns back to vbWhite.
0
 
LVL 9

Expert Comment

by:macarrillo1
ID: 40312226
Ok, So the Scenerio is:

Label1     Checkbox1a     Checkbox1b
Label2     Checkbox2a     Checkbox2b
Label3     Checkbox3a     Checkbox3b
Label4     Checkbox4a     Checkbox4b
Label5     Checkbox5a     Checkbox5b

So Label1 on Click event will:
-Change Label1 backcolor to vbYellow
-Checkbox1a will be visable
-checkbox1b will be visable

And Label1 Double Click event will:
-Change Label1 backcolor to vbWhite
-Set Checkbox1a value to false
-Set Checkbox1b value to false
-Checkbox1a hidden
-checkbox1b hidden


Does this describe what you are wanting to do?
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 40312230
Yes, exactly what I'm looking for.
0
 
LVL 9

Accepted Solution

by:
macarrillo1 earned 2000 total points
ID: 40312281
Code should look something like:

Private Sub Label1_Click()
    [Label1].BackColor = vbYellow
    CkBox1a.Visible = True
    CkBox1b.Visible = True
  
End Sub

Private Sub Label1_DblClick(Cancel As Integer)
    [Label1].BackColor = vbWhite
    CkBox1a.Value = False
    CkBox1b.Value = False
    CkBox1a.Visible = False
    CkBox1b.Visible = False

End Sub

Open in new window

0
 
LVL 9

Expert Comment

by:macarrillo1
ID: 40312286
You will have to do this for each label and the Checkboxes start off being hidden.
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 40312305
Thank you for the code. I appreciate it. Is there an easier way to write this as a function instead of doing it for each label? I was hoping to have just one function that I could call from each label with one line of code instead of creating this code for each label. For example the code I had posted that I found is 2 functions that are called from the click and dbl-click events of each label but that code does it for all the labels and not just the one I clicked on. So instead of having 5 lines of code for each label I was hoping to just call the function in one line of code for each label. Just wanted to simplify it. If not, no big deal. I can run with it like this.
0
 
LVL 9

Expert Comment

by:macarrillo1
ID: 40312389
Yes, but I am not sure you would want to go down that path.

You could use the Tag property to describe a group of controls. For example

Tag 'Gp1' would be associated with Label1, Checkbox1a and Checkbox1b
Tag 'Gp2' would be associated with Label2, Checkbox2a and Checkbox2b

Then the on click would pull the Tag for the clicked property and change the properties for all the controls with that same tag. This would require a loop to go through all controls with that Tag. You would also have to configure the all the Tags of both labels and Checkboxes.

So either you write the code for each set of controls or you manage the properties (Tags) of each of the controls and create a function to retrieve the control Tag values.

How many control sets (labels) do you have?
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 40312644
There are 53 labels and 106 checkboxes. I think going this path makes more sense than using the tag property. It sounds like much more work to do it that way. I'll keep things simple like this, even if it's more lines of code.
0
 
LVL 1

Author Closing Comment

by:Lawrence Salvucci
ID: 40312860
Thank you very much for your help. I greatly appreciate it!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question