Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Label control BackColor not responding

    I have a form with a "boat-load" of labels that depict a parking lot, snippet screenshot: Click image for larger version. 

Name:	000.jpg 
Views:	34 
Size:	10.3 KB 
ID:	44723 The depiction is to show assignment status by the back color highlighting, blue ID (number) with light gray highlighting of the stall depicting stall is assigned. The OnLoad event initializes the .BackColor highlighting as shown in the code below and works perfectly. My problem is that the .BackColor property setting subsequent to a new assignment does not take effect, specifically, the statement
    Code:
    Me.Controls("lbl" & intStallNum).BackColor = lngOColor
    New assignments start with a click on a stall ID, i.e., OnClick event "=Stall(n)" where "n" is the stall ID.



    I've run the code in Debug several times to verify that the code has the correct control but while the stall highlighting takes effect the ID label does not. I've checked "position" property to assure there's nothing astray in that arena as well as a possible corrupted form or control but nothing stands out as cause. What possibilities might I have missed?

    Code:
    Option Compare Database
    Option Explicit
    Dim lngAssigneeID As Long
    Const lngOColor As Long = 13942903      'Back color for occupied by perminent resident(s)
    Const lngStallColor As Long = 14211288    'Back color for assigned stalls
    
    Private Sub Form_Load()
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Loop through the form's control collection to see which if any stalls are
    '  already assigned and highlight accordingly.  The stall label gets highlighted
    '  in a light gray and the ID label gets a shade of blue (user's choice).
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim ctl As Control
    Dim intStallNum As Integer
    
    For Each ctl In Me.Controls
        If ctl.ControlType = acLabel Then
            If IsNumeric(Right(ctl.Caption, 3)) Then       'Stall number is last 3 of label name
                intStallNum = Right(ctl.Caption, 3)
                If Nz(DLookup("Parking", "QRegistry", "Parking = " & intStallNum)) = 0 Then
                    ctl.BackStyle = 0
                    ctl.BorderColor = 0
                Else
                    Me.Controls("lbl" & intStallNum).BackColor = lngOColor
                    Me.Controls("St" & intStallNum).BackColor = lngStallColor
                End If
            End If
        End If
    Next ctl
    
    Set ctl = Nothing
    
    End Sub
    Public Function Stall(Num As Integer)
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Parking manager has clicked on a parking stall ID label.  Could be an already
    '  assigned stall where seeking the identity of the assignee or a new assignment.
    '  A peek at the Registry afterwards will answer that question as needed.
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    
    lngAssigneeID = Nz(DLookup("RegistryID", "QRegistry", "Parking = " & Num))
    
    If lngAssigneeID > 0 Then  '>0 already assigned.  Display resident profile for what's next?
        DoCmd.OpenForm "frmRegistryDetail", , , , , acDialog, lngAssigneeID
    Else
        'Not currently assigned............. GO
        If MsgBox("Assign parking stall " & Num & "?", vbYesNo, "Stall assign option") = vbYes Then
            intAgnStall = Num    'intAgnStall is global.  Registry form will look at & reset appropriately
            DoCmd.OpenForm "frmRegistry", , , , , acDialog
            
            'Did parking stall in fact get assigned?
            If Nz(DLookup("Parking", "QRegistry", "Parking = " & Num)) = 0 Then
                Me.Controls("lbl" & Num).BackColor = 0
                Me.Controls("St" & Num).BackColor = 0
            Else
                Me.Controls("lbl" & Num).BackColor = lngOColor
                Me.Controls("St" & Num).BackColor = lngStallColor
            End If
        End If
    End If
        
    End Function
    I should note that if I close and re-open the form that ALL controls have their proper backcolor properties correct.
    Last edited by GraeagleBill; 03-20-2021 at 01:50 PM. Reason: Additional information

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Could only take a quick look because as usual, I seem to have something on the go (oven & fryer)! Try Me.Repaint on the form?
    When you change something on a form it needs to be refreshed or requeried if the change is about data (sometimes events take care of themselves) or repainted if it's not about data.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I tried a Me.Repaint but that no effect either.

    If I arbitrarily change one of the label controls to a text box, e.g., "lbl220" and "St220", and explicitly change its backcolor the change is reflected in the normal path of execution. See code:

    Code:
    Public Function Stall(Num As Integer)
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Parking manager has clicked on a parking stall ID label.  Could be an already
    '  assigned stall where seeking the identity of the assignee or a new assignment.
    '  A peek at the Registry afterwards will answer that question as needed.
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    
    lngAssigneeID = Nz(DLookup("RegistryID", "QRegistry", "Parking = " & Num))
    
    If lngAssigneeID > 0 Then  '>0 already assigned.  Display resident profile for what's next?
        DoCmd.OpenForm "frmRegistryDetail", , , , , acDialog, lngAssigneeID
    Else
        'Not currently assigned............. GO
        If MsgBox("Assign parking stall " & Num & "?", vbYesNo, "Stall assign option") = vbYes Then
            intAgnStall = Num    'intAgnStall is global.  Registry form will look at & reset appropriately
            DoCmd.OpenForm "frmRegistry", , , , , acDialog
            
            'Did parking stall in fact get assigned?
            If Nz(DLookup("Parking", "QRegistry", "Parking = " & Num)) = 0 Then
                Me.Controls("lbl" & Num).BackColor = 0
                Me.Controls("St" & Num).BackColor = 0
            Else
                Me.Controls("lbl" & Num).BackColor = lngOColor
                Me.Controls("St" & Num).BackColor = lngStallColor
    Me.tb220.BackColor = lngOColor        '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Me.St220.BackColor = lngStallColor    '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            End If
    
        End If
    
    End If
        
    End Function

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Well, one thing I question is that when you don't specify an alternate value with Nz, you get a variant and that may not be a number. Thus it may not return 0.
    Did you step through the code and check your values?

    EDIT
    Your control back style is not transparent by any chance?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Your control back style is not transparent by any chance?
    Gosh no, the form would not have worked from the get-go.

    As goofy as it might sound, there are no bound data controls on the form thus there's no RecordSource. Could it be that in the normal scheme of things Access doesn't bother to update the display? If so, I would have thought the Me.Repaint would have resolved the issue?

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    A form doesn't require a recordsource to alter label properties. After I posted that I remembered you said they worked on load, so that dispels both of our questions.
    Still wondering if you stepped through the code and validated your variables and the testing of them... like when using Nz with no value specified when null? I'm assuming that the tested value can be null and not a zls.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I tested the values extensively as I stepped through the code in Debug. Notice in the Stall Function that I set the backcolor in two label controls, the STnnn and lblnnn controls. It's only the lblnnn that doesn't repaint, its mate stnnn always repaints properly after being changed. The two labels are superimposed as you see in the OP, but I've verified the position property and all is well with that.

    It appears that I could solve this issue by converting all the labels to unbound text boxes, set and lock the values in the OnLoad event, but my stubborn nature is in the way of doing that

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Well, the overlay of controls wasn't obvious but if you want to upload a db with the minimum required I will be happy to indulge your obstinance!
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Well, first off, I see that my last reply, which would have been #9 in the thread, didn't post to the forum. Probably a pilot error at my end.

    So, on a hunch this morning I spent a bit of time developing another region of the parking facilities witch is similar enough to the offending form that the same module code applies. The additional region form works perfectly, leading me to suspect I'm dealing with a corrupted form. I will re-construct the offending from essentially from scratch and see if that resolves the OP and post the outcome.

    So, after several hours of messing around >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    OPEN Click image for larger version. 

Name:	001.jpg 
Views:	15 
Size:	4.4 KB 
ID:	44743 ASSIGN 200 Click image for larger version. 

Name:	002.jpg 
Views:	15 
Size:	3.9 KB 
ID:	44744 CLOSE & RE-OPEN Click image for larger version. 

Name:	003.jpg 
Views:	15 
Size:	4.0 KB 
ID:	44745

    If I only change the label "lbl200" to un-bound text box "tb200" and change the one line of code to change the backcolor of the text box the form works correctly. I've long since past the point of diminishing returns on this caper. Having said that, I'll likely have to admit defeat and change the controls to text boxes.
    Last edited by GraeagleBill; 03-21-2021 at 02:58 PM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-02-2019, 09:12 AM
  2. Replies: 2
    Last Post: 07-10-2017, 12:30 AM
  3. Replies: 3
    Last Post: 11-20-2015, 11:06 AM
  4. Replies: 3
    Last Post: 07-21-2013, 08:05 AM
  5. Tab Control Page Backcolor
    By RayMilhon in forum Access
    Replies: 1
    Last Post: 04-22-2013, 02:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums