【问题标题】:VBA code that changes the background color of a form after update更新后更改表单背景颜色的 VBA 代码
【发布时间】:2015-03-07 03:33:13
【问题描述】:

我需要一些代码,当未选中复选框时,它会更改表单的背景颜色,并在选中时将其恢复为原始颜色。我为复选框的代码当前锁定一个值时,请锁定一个组合框。下面的例子

Private Sub AccessKeyNo_AfterUpdate()
If MsgBox("Do you want to assign Access Key " & Me.AccessKeyNo & "?", _
        vbYesNo) = vbYes Then
    Me.GuestAccessKeyID = Me.AccessKeyNo

    If Me.Dirty Then Me.Dirty = False
    Me.AccessKeyNo.Requery
    Me.AccessKeyNo = Null

    Me.MyCheckBox = IsNull(Me.GuestAccessKeyID)
End If
End Sub

【问题讨论】:

    标签: ms-access vba


    【解决方案1】:

    在标准模块中(不是表单模块——常量的范围仅限于表单,因此您将无法重用它们):

    Public Const colorBlue_Cornflower = "15714765"
    Public Const colorTan_Encarnacion = "11398133"
    

    现在在表单模块中:

    Dim colorThis as String, booWhatever as Boolean
    
    booWhatever = Me.MyCheckBox  ''Use of the variable can prevent problems
    
    If booWhatever Then
         colorThis = colorBlue_Cornflower
    Else
         colorThis = colorTan_Encarnacion 
    End If
    
    subFrm.Form.Section(acDetail).BackColor = colorThis 
    subFrm.Form.Section(acHeader).BackColor = colorThis 
    
    subFrm.Form.Repaint
    

    【讨论】:

    • 谢谢,但你能告诉我 Public Const colorBlue....会在我的代码中的什么位置吗?
    • 它只需要进入标准模块的标题区域即可。不是表单模块,很抱歉没有说清楚。分配常量只是为了方便,但由于我将此更改应用于其他形式,因此实际上不仅仅是方便。您可能需要对“subFrm”进行一些说明。还有……
    猜你喜欢
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多