Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org
FAQs

Terms of Use

API: Calling Windows Choose Color Dialog

Author(s)
Terry Kreft
& Stephen Lebans

To call Windows ChooseColor dialog from code, we can use the ChooseColor API function.

Choose Font or Color Dialog.zip (Access 97)

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 ********
'This code was originally written by Terry Kreft,
'and modified by Stephen Lebans
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
' 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 ***********

1998-2002, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer