If you use the optional code, the ctl's backcolor will be the number of the
color selected.
Here is the amended code:
' ******** 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 (e-mail address removed)
'
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 DialogColor(ctl As Control) As Long
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
ctl.BackColor = RGB(255, 255, 255) ' White
DialogColor = False
Exit Function
Else
' Normal processing
ctl.BackColor = CS.rgbResult
End If
DialogColor = True
DialogColor = CS.rgbResult
End Function
' ********* Code End ***********
So, just add a field to your table, set to number, single, to hold the
color selected by the user. Then, assign the backcolor to a textbox -
Private Sub Command0_Click()
' Pass the TextBox Control to the function
Me.Text1.BackColor = DialogColor(Me.Text1)
Me.Text3 = Me.Text1.BackColor
'Text3 can be a hidden textbox bound to the field that holds the backcolor
number.
End Sub
Private Sub Form_Current()
If Not Me.NewRecord Then
Me.Text1.BackColor = Me.Text3
Else
Me.Text1.BackColor = vbWhite
End If
End Sub
Damon
Ok I was able to find one piece of the equation regarding pick a color
(
http://www.mvps.org/access/api/api0060.htm) , however I am unble to store
the color code and I still need to find a way to reproduce the code once
the
record is retieve. I am sure someone out there is ablke to get it to work.
The code I found is:
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 (e-mail address removed)
'
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 users need to fill in a report in which they need to describe the
color of
the object (water, soil or whatever) observed during an inspection. Is
there
a way for them to pick a color from the color selection window in access
and
store that color code in a table field and then have a control or label
in a
form to display the actual color (e.g. small red box)? Of course, each
record
will display the color selected. Also, most likely I will be using
continuous
form in order to view all my records.
Thank you,
Silvio
P.s. I have posted this question in the wrong group before (Form Design
so
disregard it in Form Design group since this is more coding)