473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Combo box to select colors

Hi,

How can I use then Windows' color picker from Access?

Thx
May 20 '06 #1
4 6656
You can use API calls. Paste the following into a standard module. There
is an example of it's use at the bottom.

Option Explicit

Private Const CDERR_DIALOGFAILURE = &HFFFF
Private Const CDERR_FINDRESFAILURE = &H6
Private Const CDERR_GENERALCODES = &H0
Private Const CDERR_INITIALIZATION = &H2
Private Const CDERR_LOADRESFAILURE = &H7
Private Const CDERR_LOADSTRFAILURE = &H5
Private Const CDERR_LOCKRESFAILURE = &H8
Private Const CDERR_MEMALLOCFAILURE = &H9
Private Const CDERR_MEMLOCKFAILURE = &HA
Private Const CDERR_NOHINSTANCE = &H4
Private Const CDERR_NOHOOK = &HB
Private Const CDERR_NOTEMPLATE = &H3
Private Const CDERR_REGISTERMSGFAIL = &HC
Private Const CDERR_STRUCTSIZE = &H1

Private Const CC_FULLOPEN = &H2
Private Const CC_PREVENTFULLOPEN = &H4
Private Const CC_RGBINIT = &H1

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

Private Declare Function ChooseColorDlg _
Lib "comdlg32.dll" Alias "ChooseColorA" ( _
pChoosecolor As CHOOSECOLOR _
) As Long

Private Declare Function CommDlgExtendedError _
Lib "comdlg32.dll" () As Long

Private Declare Sub CopyMemory _
Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long _
)
Public Function GetColor(lngHwnd As Long, arrCustColors() As Long, InitColor
As Long) As Boolean
Dim lngRet As Long
Dim intCount As Integer
Dim CC As CHOOSECOLOR

With CC
.lStructSize = Len(CC)
.flags = CC_FULLOPEN + CC_RGBINIT
.hwndOwner = lngHwnd
.lpCustColors = VarPtr(arrCustColors(0))
.rgbResult = InitColor
End With

GetColor = CBool(ChooseColorDlg(CC))
If GetColor Then
ReDim arrRet(0 To 15)
Call CopyMemory(arrRet(0), ByVal CC.lpCustColors, 64)
InitColor = CC.rgbResult
Else
lngRet = CommDlgExtendedError
Debug.Print lngRet
Select Case lngRet
Case CDERR_DIALOGFAILURE
Case CDERR_FINDRESFAILURE
Case CDERR_MEMLOCKFAILURE
Case CDERR_INITIALIZATION
Case CDERR_NOHINSTANCE
Case CDERR_LOCKRESFAILURE
Case CDERR_NOHOOK
Case CDERR_LOADRESFAILURE
Case CDERR_NOTEMPLATE
Case CDERR_LOADSTRFAILURE
Case CDERR_STRUCTSIZE
Case CDERR_MEMALLOCFAILURE
End Select
End If
End Function

Create a new form and put a command button (Command0) on the form pate th
ollowing code into the ommand buttons click event.

Private Sub Command0_Click()
Dim lngColor As Long
Dim arrCustColors() As Long

lngColor = Me.Command0.ForeColor
ReDim arrCustColors(0 To 15)
If GetColor(Me.Hwnd, arrCustColors(), lngColor) Then
Me.Command0.ForeColor = lngColor
End If

End Sub

Change to Form view click on the button and select a colour from the dialog.

Note: The arrCustColors array returns the colour values of any custom
colours you define. You can then persist these and reinitialize the dialog
pasing those values back in to initialise the custom colours.
--

Terry Kreft
"Michel" <mi***********@yahoo.ca> wrote in message
news:1n*********************@wagner.videotron.net. ..
Hi,

How can I use then Windows' color picker from Access?

Thx

May 21 '06 #2
Thanks

"Terry Kreft" <te*********@mps.co.uk> a écrit dans le message de news:
Ha********************@karoo.co.uk...
You can use API calls. Paste the following into a standard module. There
is an example of it's use at the bottom.

Option Explicit

Private Const CDERR_DIALOGFAILURE = &HFFFF
Private Const CDERR_FINDRESFAILURE = &H6
Private Const CDERR_GENERALCODES = &H0
Private Const CDERR_INITIALIZATION = &H2
Private Const CDERR_LOADRESFAILURE = &H7
Private Const CDERR_LOADSTRFAILURE = &H5
Private Const CDERR_LOCKRESFAILURE = &H8
Private Const CDERR_MEMALLOCFAILURE = &H9
Private Const CDERR_MEMLOCKFAILURE = &HA
Private Const CDERR_NOHINSTANCE = &H4
Private Const CDERR_NOHOOK = &HB
Private Const CDERR_NOTEMPLATE = &H3
Private Const CDERR_REGISTERMSGFAIL = &HC
Private Const CDERR_STRUCTSIZE = &H1

Private Const CC_FULLOPEN = &H2
Private Const CC_PREVENTFULLOPEN = &H4
Private Const CC_RGBINIT = &H1

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

Private Declare Function ChooseColorDlg _
Lib "comdlg32.dll" Alias "ChooseColorA" ( _
pChoosecolor As CHOOSECOLOR _
) As Long

Private Declare Function CommDlgExtendedError _
Lib "comdlg32.dll" () As Long

Private Declare Sub CopyMemory _
Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long _
)
Public Function GetColor(lngHwnd As Long, arrCustColors() As Long, InitColor As Long) As Boolean
Dim lngRet As Long
Dim intCount As Integer
Dim CC As CHOOSECOLOR

With CC
.lStructSize = Len(CC)
.flags = CC_FULLOPEN + CC_RGBINIT
.hwndOwner = lngHwnd
.lpCustColors = VarPtr(arrCustColors(0))
.rgbResult = InitColor
End With

GetColor = CBool(ChooseColorDlg(CC))
If GetColor Then
ReDim arrRet(0 To 15)
Call CopyMemory(arrRet(0), ByVal CC.lpCustColors, 64)
InitColor = CC.rgbResult
Else
lngRet = CommDlgExtendedError
Debug.Print lngRet
Select Case lngRet
Case CDERR_DIALOGFAILURE
Case CDERR_FINDRESFAILURE
Case CDERR_MEMLOCKFAILURE
Case CDERR_INITIALIZATION
Case CDERR_NOHINSTANCE
Case CDERR_LOCKRESFAILURE
Case CDERR_NOHOOK
Case CDERR_LOADRESFAILURE
Case CDERR_NOTEMPLATE
Case CDERR_LOADSTRFAILURE
Case CDERR_STRUCTSIZE
Case CDERR_MEMALLOCFAILURE
End Select
End If
End Function

Create a new form and put a command button (Command0) on the form pate th
ollowing code into the ommand buttons click event.

Private Sub Command0_Click()
Dim lngColor As Long
Dim arrCustColors() As Long

lngColor = Me.Command0.ForeColor
ReDim arrCustColors(0 To 15)
If GetColor(Me.Hwnd, arrCustColors(), lngColor) Then
Me.Command0.ForeColor = lngColor
End If

End Sub

Change to Form view click on the button and select a colour from the dialog.
Note: The arrCustColors array returns the colour values of any custom
colours you define. You can then persist these and reinitialize the dialog pasing those values back in to initialise the custom colours.
--

Terry Kreft
"Michel" <mi***********@yahoo.ca> wrote in message
news:1n*********************@wagner.videotron.net. ..
Hi,

How can I use then Windows' color picker from Access?

Thx


May 21 '06 #3
Thanks, but how and where do I define arrRet(0)?
It doesn't compile as it is.

"Terry Kreft" <te*********@mps.co.uk> a écrit dans le message de news:
Ha********************@karoo.co.uk...
You can use API calls. Paste the following into a standard module. There
is an example of it's use at the bottom.

Option Explicit

Private Const CDERR_DIALOGFAILURE = &HFFFF
Private Const CDERR_FINDRESFAILURE = &H6
Private Const CDERR_GENERALCODES = &H0
Private Const CDERR_INITIALIZATION = &H2
Private Const CDERR_LOADRESFAILURE = &H7
Private Const CDERR_LOADSTRFAILURE = &H5
Private Const CDERR_LOCKRESFAILURE = &H8
Private Const CDERR_MEMALLOCFAILURE = &H9
Private Const CDERR_MEMLOCKFAILURE = &HA
Private Const CDERR_NOHINSTANCE = &H4
Private Const CDERR_NOHOOK = &HB
Private Const CDERR_NOTEMPLATE = &H3
Private Const CDERR_REGISTERMSGFAIL = &HC
Private Const CDERR_STRUCTSIZE = &H1

Private Const CC_FULLOPEN = &H2
Private Const CC_PREVENTFULLOPEN = &H4
Private Const CC_RGBINIT = &H1

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

Private Declare Function ChooseColorDlg _
Lib "comdlg32.dll" Alias "ChooseColorA" ( _
pChoosecolor As CHOOSECOLOR _
) As Long

Private Declare Function CommDlgExtendedError _
Lib "comdlg32.dll" () As Long

Private Declare Sub CopyMemory _
Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long _
)
Public Function GetColor(lngHwnd As Long, arrCustColors() As Long, InitColor As Long) As Boolean
Dim lngRet As Long
Dim intCount As Integer
Dim CC As CHOOSECOLOR

With CC
.lStructSize = Len(CC)
.flags = CC_FULLOPEN + CC_RGBINIT
.hwndOwner = lngHwnd
.lpCustColors = VarPtr(arrCustColors(0))
.rgbResult = InitColor
End With

GetColor = CBool(ChooseColorDlg(CC))
If GetColor Then
ReDim arrRet(0 To 15)
Call CopyMemory(arrRet(0), ByVal CC.lpCustColors, 64)
InitColor = CC.rgbResult
Else
lngRet = CommDlgExtendedError
Debug.Print lngRet
Select Case lngRet
Case CDERR_DIALOGFAILURE
Case CDERR_FINDRESFAILURE
Case CDERR_MEMLOCKFAILURE
Case CDERR_INITIALIZATION
Case CDERR_NOHINSTANCE
Case CDERR_LOCKRESFAILURE
Case CDERR_NOHOOK
Case CDERR_LOADRESFAILURE
Case CDERR_NOTEMPLATE
Case CDERR_LOADSTRFAILURE
Case CDERR_STRUCTSIZE
Case CDERR_MEMALLOCFAILURE
End Select
End If
End Function

Create a new form and put a command button (Command0) on the form pate th
ollowing code into the ommand buttons click event.

Private Sub Command0_Click()
Dim lngColor As Long
Dim arrCustColors() As Long

lngColor = Me.Command0.ForeColor
ReDim arrCustColors(0 To 15)
If GetColor(Me.Hwnd, arrCustColors(), lngColor) Then
Me.Command0.ForeColor = lngColor
End If

End Sub

Change to Form view click on the button and select a colour from the dialog.
Note: The arrCustColors array returns the colour values of any custom
colours you define. You can then persist these and reinitialize the dialog pasing those values back in to initialise the custom colours.
--

Terry Kreft
"Michel" <mi***********@yahoo.ca> wrote in message
news:1n*********************@wagner.videotron.net. ..
Hi,

How can I use then Windows' color picker from Access?

Thx


May 21 '06 #4

It does compile I tested it before I posted.

There is sample code at the end, I'll post it again here. See the comment in
the code as the answer to your question.

Create a new form and put a command button (Command0) on the form paste the
following code into the command buttons click event.
Private Sub Command0_Click()
Dim lngColor As Long
Dim arrCustColors() As Long

lngColor = Me.Command0.ForeColor

' ************************************************** ***
' To answer your question this is where arrCustColors is dimensioned
' before it is passed to the GetColor function
' ************************************************** ***
ReDim arrCustColors(0 To 15)
If GetColor(Me.Hwnd, arrCustColors(), lngColor) Then
Me.Command0.ForeColor = lngColor
End If
End Sub
--

Terry Kreft
"Michel" <mi***********@yahoo.ca> wrote in message
news:wf********************@wagner.videotron.net.. .
Thanks, but how and where do I define arrRet(0)?
It doesn't compile as it is.

"Terry Kreft" <te*********@mps.co.uk> a écrit dans le message de news:
Ha********************@karoo.co.uk...
You can use API calls. Paste the following into a standard module. There is an example of it's use at the bottom.

Option Explicit

Private Const CDERR_DIALOGFAILURE = &HFFFF
Private Const CDERR_FINDRESFAILURE = &H6
Private Const CDERR_GENERALCODES = &H0
Private Const CDERR_INITIALIZATION = &H2
Private Const CDERR_LOADRESFAILURE = &H7
Private Const CDERR_LOADSTRFAILURE = &H5
Private Const CDERR_LOCKRESFAILURE = &H8
Private Const CDERR_MEMALLOCFAILURE = &H9
Private Const CDERR_MEMLOCKFAILURE = &HA
Private Const CDERR_NOHINSTANCE = &H4
Private Const CDERR_NOHOOK = &HB
Private Const CDERR_NOTEMPLATE = &H3
Private Const CDERR_REGISTERMSGFAIL = &HC
Private Const CDERR_STRUCTSIZE = &H1

Private Const CC_FULLOPEN = &H2
Private Const CC_PREVENTFULLOPEN = &H4
Private Const CC_RGBINIT = &H1

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

Private Declare Function ChooseColorDlg _
Lib "comdlg32.dll" Alias "ChooseColorA" ( _
pChoosecolor As CHOOSECOLOR _
) As Long

Private Declare Function CommDlgExtendedError _
Lib "comdlg32.dll" () As Long

Private Declare Sub CopyMemory _
Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long _
)
Public Function GetColor(lngHwnd As Long, arrCustColors() As Long,

InitColor
As Long) As Boolean
Dim lngRet As Long
Dim intCount As Integer
Dim CC As CHOOSECOLOR

With CC
.lStructSize = Len(CC)
.flags = CC_FULLOPEN + CC_RGBINIT
.hwndOwner = lngHwnd
.lpCustColors = VarPtr(arrCustColors(0))
.rgbResult = InitColor
End With

GetColor = CBool(ChooseColorDlg(CC))
If GetColor Then
ReDim arrRet(0 To 15)
Call CopyMemory(arrRet(0), ByVal CC.lpCustColors, 64)
InitColor = CC.rgbResult
Else
lngRet = CommDlgExtendedError
Debug.Print lngRet
Select Case lngRet
Case CDERR_DIALOGFAILURE
Case CDERR_FINDRESFAILURE
Case CDERR_MEMLOCKFAILURE
Case CDERR_INITIALIZATION
Case CDERR_NOHINSTANCE
Case CDERR_LOCKRESFAILURE
Case CDERR_NOHOOK
Case CDERR_LOADRESFAILURE
Case CDERR_NOTEMPLATE
Case CDERR_LOADSTRFAILURE
Case CDERR_STRUCTSIZE
Case CDERR_MEMALLOCFAILURE
End Select
End If
End Function

Create a new form and put a command button (Command0) on the form pate th ollowing code into the ommand buttons click event.

Private Sub Command0_Click()
Dim lngColor As Long
Dim arrCustColors() As Long

lngColor = Me.Command0.ForeColor
ReDim arrCustColors(0 To 15)
If GetColor(Me.Hwnd, arrCustColors(), lngColor) Then
Me.Command0.ForeColor = lngColor
End If

End Sub

Change to Form view click on the button and select a colour from the

dialog.

Note: The arrCustColors array returns the colour values of any custom
colours you define. You can then persist these and reinitialize the

dialog
pasing those values back in to initialise the custom colours.
--

Terry Kreft
"Michel" <mi***********@yahoo.ca> wrote in message
news:1n*********************@wagner.videotron.net. ..
Hi,

How can I use then Windows' color picker from Access?

Thx



May 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: palmiere | last post by:
Im trying to do the following: I have 2 select boxes, both are pre populated with data. The first box is a single select box, the 2nd is a multiple select box. Depending on the 1st selection, I...
13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
3
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
5
by: T_2k | last post by:
I am trying to setup a search facility, such that anything selected in any of 5 comboboxes is used as criteria unless null or "". I only want to get back results where ALL selections are in a...
5
by: consonanza | last post by:
I am working on a report filter form. It has 2 combo boxes (cmboSelectSubject and cmboSelectCategory) to select criteria. Selecting an entry in combo 1 restricts the options available in combo 2....
2
by: SM | last post by:
Hello, I have an HTML file that contains a form with 2 selection list (combo box). The first combobox 'onchange' function, addColor(),adds a new color to the second combobox. I have half of the...
2
by: Vinnie the Rat | last post by:
I need to provide a pick list for a data entry field. I do everything but take the selected value and get it into the dataset for eventual update to the the database. I can show the field of the...
3
by: evenlater | last post by:
Using Access 2007, I've found that combo box back colors change to transparent from normal inconsistently for no reason I can discern. Never had that problem in previous versions of Access. I do...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.