VBA code表示更新后改变表格的背景颜色 [英] VBA code that changes the background color of a form after update
本文介绍了VBA code表示更新后改变表格的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些code,当一个复选框选中它将改变我的窗体的背景颜色和检查时,将其返回到原来的颜色。在codeI有复选框目前锁定了一个组合框选择的值时。以下
例 私人小组AccessKeyNo_AfterUpdate()
如果MSGBOX(你要分配访问密钥&放大器; Me.AccessKeyNo&安培;?,_
vbYesNo)= vbYes然后
Me.GuestAccessKeyID = Me.AccessKeyNo
如果Me.Dirty然后Me.Dirty = FALSE
Me.AccessKeyNo.Requery
Me.AccessKeyNo = NULL
Me.MyCheckBox = ISNULL(Me.GuestAccessKeyID)
结束如果
结束小组
解决方案
在一个标准模块(而非窗体模块 - 常量的范围将仅限于形式,因此,你将无法再使用它们)
公共常量colorBlue_Cornflower =15714765
公共常量colorTan_Encarnacion =11398133
现在在模块的形式:
暗淡colorThis为String,booWhatever布尔
booWhatever = Me.MyCheckBox''使用的变量可以prevent问题
如果booWhatever然后
colorThis = colorBlue_Cornflower
其他
colorThis = colorTan_Encarnacion
结束如果
subFrm.Form.Section(acDetail).BackColor = colorThis
subFrm.Form.Section(acHeader).BackColor = colorThis
subFrm.Form.Repaint
I need some code that when a check box is unchecked it will change the background color of my form and return it back to its original color when checked. The code i have for the check box currently locks a combo box when a value is chosen. Example below
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
解决方案
In a standard module (not the form module -- the scope of the constants would be limited to form, thus you wouldn't be able to reuse them):
Public Const colorBlue_Cornflower = "15714765"
Public Const colorTan_Encarnacion = "11398133"
Now in the module for the form:
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
这篇关于VBA code表示更新后改变表格的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文