访问无效限定符

时间:2016-03-12 12:51:39

标签: vba ms-access access-vba

Private Sub Form_Load()

Dim BX As String
Set DBase = CurrentDb
Dim RSColours As DAO.Recordset
Set RSColours = DBase.OpenRecordset("Colours")
RSColours.MoveFirst
Do While Not RSColours.EOF
MsgBox "ZoneCode  " & RSColours!Zonecode
R = Val("&H" & Mid(RSColours![Zonecode], 1, 2))
G = Val("&H" & Mid(RSColours![Zonecode], 3, 2))
B = Val("&H" & Mid(RSColours![Zonecode], 5, 2))

BX = RSColours![Sheetzone]
                'MsgBox "length  " & BX & "   " & Len(BX)
                'MsgBox R & "/" & G & "/" & B

'BX.BackColor = RGB(R, G, B)'..............................Fails here even though BX ?= B1Z1
B1Z1.BackColor = RGB(R, G, B) '.............................Works, but I want to color more than one rectangle
RSColours.MoveNext
Loop
End Sub

我为几个矩形着色并将矩形名称(B1Z1等)和HexColor保存到表格中。当我重新加载表单时,我想恢复保存的颜色。 分配变量(BX)并尝试设置Backcolor时程序失败。

如果我使用常量“B1Z1”,这是有效的。我正在尝试的是什么。?

1 个答案:

答案 0 :(得分:0)

您需要字符串对象:

Me(BX).BackColor = RGB(R, G, B)