استخدم هذا الكود وسيعمل معك على الإصدارتين
#If VBA7 Then
Private Type ChooseColor
lStructSize As Long
hwndOwner As LongPtr
hInstance As LongPtr
rgbResult As Long
lpCustColors As LongPtr
flags As Long
lCustData As LongPtr
lpfnHook As LongPtr
lpTemplateName As String
End Type
#Else
Private Type ChooseColor
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
#End If
Private Const CC_ANYCOLOR = &H100
'Private Const CC_ENABLEHOOK = &H10
'Private Const CC_ENABLETEMPLATE = &H20
'Private Const CC_ENABLETEMPLATEHANDLE = &H40
Private Const CC_FULLOPEN = &H2
Private Const CC_PREVENTFULLOPEN = &H4
Private Const CC_RGBINIT = &H1
'Private Const CC_SHOWHELP = &H8
'Private Const CC_SOLIDCOLOR = &H80
#If VBA7 Then
Private Declare PtrSafe Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As ChooseColor) As Long
#Else
Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As ChooseColor) As Long
#End If
Public Function DialogColor(Optional lDefaultColor As Variant) As Long
Dim CC As ChooseColor
Dim lRetVal As Long
Static CustomColors(16) As Long
'Some predefined color, there are 16 slots available for predefined colors
'You don't have to defined any, if you don't want to!
CustomColors(0) = RGB(255, 255, 255) 'White
CustomColors(1) = RGB(0, 0, 0) 'Black
CustomColors(2) = RGB(255, 0, 0) 'Red
CustomColors(3) = RGB(0, 255, 0) 'Green
CustomColors(4) = RGB(0, 0, 255) 'Blue
With CC
.lStructSize = LenB(CC)
.hwndOwner = Application.hWndAccessApp
.flags = CC_ANYCOLOR Or CC_FULLOPEN Or CC_PREVENTFULLOPEN Or CC_RGBINIT
If IsNull(lDefaultColor) = False _
And IsMissing(lDefaultColor) = False Then .rgbResult = lDefaultColor 'Set the initial color of the dialog
.lpCustColors = VarPtr(CustomColors(0))
End With
lRetVal = ChooseColor(CC)
If lRetVal = 0 Then
'Cancelled by the user
DialogColor = RGB(255, 255, 255) ' White -> 16777215
Else
DialogColor = CC.rgbResult
End If
End Function