I have developed an application, which allows users to run queries and see their results in Powerpoint graphs (MS Graph), through Automation.
The process works fine. Looping through the DataSeries and using different SchemeColor codes I get the desired graph using code like this:
If k = 3 Then
With shpGraph.SeriesCollection(k)
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 38
End With
Where, k is the DataSeries number and 38 the color as an index into the color palette (ColorIndex Property).
HOWEVER, my objective is to be able to call the Windows ChooseColor dialog form, allow the user to select a color (from the standard set or custom), store in a table the code of each color selected (in RGB code), then pass all the RGB codes as parameters to the function and use them to produce a graph with user-defined colors.
Courtesy of The Acces Web ( I have found this little code:
API: Calling Windows Choose Color Dialog
To call Windows ChooseColor dialog from code, we can use the
ChooseColor API function.
If you want this function to simply return the value of the Color
the user selected from the Dialog, then just change the function
declaration in modColorPicker to something like:
Public Function DialogColor(ctl As Control) As Long
' Remember to add the line of code at the
' end of the Function
' DialogColor = CS.rgbResult
Then call it from your Form with code like:
'***Code Start ***
Private Sub CmdChooseBackColor_Click()
' Pass the TextBox Control to the function
Me.textCtl.BackColor = DialogColor(Me.textCtl)
End Sub
'***Code End ***
' ******** Code Start ********
' Original Code by Terry Kreft
' Modified by Stephen Lebans
' Contact Stephen@lebans.com
'
Private Type COLORSTRUC
lStructSize As Long
hwnd As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
Flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Const CC_SOLIDCOLOR = &H80
Private Declare Function ChooseColor _
Lib "comdlg32.dll" Alias "ChooseColorA" _
(pChoosecolor As COLORSTRUC) As Long
Public Function aDialogColor(prop As Property) As Boolean
Dim x As Long, CS As COLORSTRUC, CustColor(16) As Long
CS.lStructSize = Len(CS)
CS.hwnd = hWndAccessApp
CS.Flags = CC_SOLIDCOLOR
CS.lpCustColors = String$(16 * 4, 0)
x = ChooseColor(CS)
If x = 0 Then
' ERROR - use Default White
prop = RGB(255, 255, 255) ' White
aDialogColor = False
Exit Function
Else
' Normal processing
prop = CS.rgbResult
End If
aDialogColor = True
End Function
' ********* Code End ***********
My problem is the code returned by the program. For example for White it returns 16777215 which although used by Access to change the color of a text box, I cannot use for my purpose. What I want returned is 255, 255, 255 for RGB. For Blue it returns 16711808 which is in fact 128, 0, 255.
I have been able to "decode" these numbers as follows:
16777215 is 255x256^0 + 255x256^1 +255x256^2 and
16711808 is 128x256^0 + 0x256^1 +255x256^2
where the symbol ^ means of course "raised to the power of"
Can anybody help me work the other way round e.g. get the number used by Access to change the property of a text box on a form and "translate" it to RGB ? Or even better provide code that would allow me to 'map' the color returned by the Windows ChooseColor dialog form to the index codes used by MS Graph?
Any help will be greatly appreciated.
Regards Cosmark
The process works fine. Looping through the DataSeries and using different SchemeColor codes I get the desired graph using code like this:
If k = 3 Then
With shpGraph.SeriesCollection(k)
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 38
End With
Where, k is the DataSeries number and 38 the color as an index into the color palette (ColorIndex Property).
HOWEVER, my objective is to be able to call the Windows ChooseColor dialog form, allow the user to select a color (from the standard set or custom), store in a table the code of each color selected (in RGB code), then pass all the RGB codes as parameters to the function and use them to produce a graph with user-defined colors.
Courtesy of The Acces Web ( I have found this little code:
API: Calling Windows Choose Color Dialog
To call Windows ChooseColor dialog from code, we can use the
ChooseColor API function.
If you want this function to simply return the value of the Color
the user selected from the Dialog, then just change the function
declaration in modColorPicker to something like:
Public Function DialogColor(ctl As Control) As Long
' Remember to add the line of code at the
' end of the Function
' DialogColor = CS.rgbResult
Then call it from your Form with code like:
'***Code Start ***
Private Sub CmdChooseBackColor_Click()
' Pass the TextBox Control to the function
Me.textCtl.BackColor = DialogColor(Me.textCtl)
End Sub
'***Code End ***
' ******** Code Start ********
' Original Code by Terry Kreft
' Modified by Stephen Lebans
' Contact Stephen@lebans.com
'
Private Type COLORSTRUC
lStructSize As Long
hwnd As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
Flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Const CC_SOLIDCOLOR = &H80
Private Declare Function ChooseColor _
Lib "comdlg32.dll" Alias "ChooseColorA" _
(pChoosecolor As COLORSTRUC) As Long
Public Function aDialogColor(prop As Property) As Boolean
Dim x As Long, CS As COLORSTRUC, CustColor(16) As Long
CS.lStructSize = Len(CS)
CS.hwnd = hWndAccessApp
CS.Flags = CC_SOLIDCOLOR
CS.lpCustColors = String$(16 * 4, 0)
x = ChooseColor(CS)
If x = 0 Then
' ERROR - use Default White
prop = RGB(255, 255, 255) ' White
aDialogColor = False
Exit Function
Else
' Normal processing
prop = CS.rgbResult
End If
aDialogColor = True
End Function
' ********* Code End ***********
My problem is the code returned by the program. For example for White it returns 16777215 which although used by Access to change the color of a text box, I cannot use for my purpose. What I want returned is 255, 255, 255 for RGB. For Blue it returns 16711808 which is in fact 128, 0, 255.
I have been able to "decode" these numbers as follows:
16777215 is 255x256^0 + 255x256^1 +255x256^2 and
16711808 is 128x256^0 + 0x256^1 +255x256^2
where the symbol ^ means of course "raised to the power of"
Can anybody help me work the other way round e.g. get the number used by Access to change the property of a text box on a form and "translate" it to RGB ? Or even better provide code that would allow me to 'map' the color returned by the Windows ChooseColor dialog form to the index codes used by MS Graph?
Any help will be greatly appreciated.
Regards Cosmark