gpt4 book ai didi

ms-access - 在 VBA 中设置 Access 颜色代码

转载 作者:行者123 更新时间:2023-12-04 12:49:52 25 4
gpt4 key购买 nike

我在 Access 数据库中设置文本框的背景颜色时遇到问题。我想在满足某些条件时将颜色更改为红色。

在设计 View 中,我已将文本框的背景颜色属性设置为红色,并显示为“#ED1C24”。当我在窗体 View 中查看窗体时,控件以我选择的红色正确显示。

但是,当我将此值放入 VBA 代码 (Text1.Backcolor = "#ED1C24") 时,出现类型不匹配错误。

我尝试将其更改为十六进制数 (Text1.Backcolor = &HED1C24),但随后控件变为蓝色。

任何帮助,将不胜感激。谢谢。

最佳答案

不久前我写了一篇关于这个问题的博客,应该可以回答你的问题。

http://www.jht.co.uk/access-colour-color-codes/

这是代码:

Public Function HTMLColour(HTMLCode As String, Optional Red As Variant, _
Optional Green As Variant, Optional Blue As Variant) As Long
On Error GoTo HTMLColour_Error

'Converts an HTML colour code number to a long interger
'Also returns the constituent R,G & B components through supplied parameters

Dim intR As Integer, intG As Integer, intB As Integer
Dim strHTML As String

'Strip # prefix if supplied
If Len(HTMLCode) < 6 Then Exit Function
strHTML = Right(HTMLCode, 6)

'Extract R, G, B values
intR = CInt("&H" & Mid(strHTML, 1, 2))
intG = CInt("&H" & Mid(strHTML, 3, 2))
intB = CInt("&H" & Mid(strHTML, 5, 2))

'Return optional parameters
If Not IsMissing(Red) Then Red = intR
If Not IsMissing(Green) Then Green = intG
If Not IsMissing(Blue) Then Blue = intB

'Convert RGB to Long integer
HTMLColour = RGB(intR, intG, intB)

HTMLColour_Exit:
Exit Function

HTMLColour_Error:
MsgBox Err.Description, vbExclamation, "Function HTMLColour"
Resume HTMLColour_Exit
End Function

希望这可以帮助。

关于ms-access - 在 VBA 中设置 Access 颜色代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40588470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com