asked on
ASKER
Option Compare Database
Option Explicit
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
FunctionText.BackColor = [BackColor]
FunctionText.ForeColor = [ForeColor]
End Sub
where BackColor and ForeColor are the columns in your data source. Don't hardcode the fore color (white/black) either.
In VBA, you can't use the hex values.
Option Compare Database
Option Explicit
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
FunctionText.BackColor = &H112233
FunctionText.ForeColor = &H998877
End Sub
The thing you need to now, the hex value in VBA is the hex VBA internal color representation. It is not RGB, its BGR. Thus the order of the color bytes is different then the hex web notation using the hash.
' Returns the numeric RGB value from an CSS RGB hex representation.
' Will accept strings with or without a leading octothorpe.
'
' Examples:
' Color = RGBCompound("#9A690C")
' ' Color = 813466
' Color = RGBCompound("9A690C")
' ' Color = 813466
'
' 2017-03-26. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function RGBCompound( _
ByVal HexRGB As String) _
As Long
' Format of RGB hex strings.
Const RGBPrefix As String = "#"
Const Length As Integer = 6
' Format of Hex values.
Const HexPrefix As String = "&H"
Dim Start As Integer
Dim Color As Long
If Mid(HexRGB, 1, 1) = RGBPrefix Then
Start = 1
End If
If Len(HexRGB) = Start + Length Then
Color = RGB( _
HexPrefix & Mid(HexRGB, Start + 1, 2), _
HexPrefix & Mid(HexRGB, Start + 3, 2), _
HexPrefix & Mid(HexRGB, Start + 5, 2))
End If
RGBCompound = Color
End Function
Full info and more colour functions here: VBA.ModernTheme.
Option Compare Database
Option Explicit
Public Sub TestColors()
' https://en.wikipedia.org/wiki/Web_colors#HTML_color_names
' CSS 1–2.0, HTML 3.2–4, and VGA color names
' Name Hex
' Red #FF0000
' Green #008000
' Blue #0000FF
Debug.Print Right("000000" & Hex(vbBlue), 6)
Debug.Print Right("000000" & Hex(vbGreen), 6)
Debug.Print Right("000000" & Hex(vbRed), 6)
End Sub
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
TRUSTED BY