通过字符串提供控件名称

时间:2019-02-06 12:57:53

标签: access-vba

“ Me.strLblName.FontBold = True”不起作用。我已经尝试过Me。&strLblName&.FontBold = True和其他许多东西。这是语法问题还是我需要其他方法?

**Private Sub Form_Load()
Dim ctl As Control, intUsage As Integer, strCtlName As String, strLblName As String
For Each ctl In Me.Form.Controls
    Select Case ctl.ControlType
        Case acCommandButton
            intUsage = DLookup("process_usage", "tbl_db_stats", "cbtn_name = '" & ctl.Name & "'")
            Debug.Print ctl.ControlType, ctl.Name, intUsage
            strLblName = "lbl_" & Right(ctl.Name, Len(ctl.Name) - 5)
            If intUsage < 10 Then
                Stop
                'CHANGE LABEL TEXT TO BOLD
                Me.strLblName.FontBold = True
            End If
    End Select
Next ctl
End Sub**

1 个答案:

答案 0 :(得分:0)

Controls(strLblName).FontBold = True