I have a form with a "boat-load" of labels that depict a parking lot, snippet screenshot: 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.