Re: Color Picking

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




Thank you very much Damon, it appears to work just fine “Single Form” view,
however, when using “Continuous Form” then each record (Text1) displays the
same color, then when a different record receive the focus that new color
will also change for all the records in the form. It appears to me that
probably conditional formatting could do the trick by having a code in form
open or current that would be something like:

if not IsNull([Text3]) then
Text1.backcolor = [Text3]
Else
Text1.backcolor = vbWhite

I have no idea of the vb codes for conditional formatting, if you can help I
really appreciate it.


"Damon Heron" wrote:

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 Stephen@xxxxxxxxxx
'
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



"Silvio" <Silvio@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A81DAC21-0A71-4D4F-9D82-F1D397FF954E@xxxxxxxxxxxxxxxx
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 Stephen@xxxxxxxxxx
'
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 ***********




"Silvio" wrote:

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)



.



Relevant Pages

  • Re: Color Picking
    ... Yes, I noticed later that you said continuous form view, I have since looked ... Private Type COLORSTRUC ... Private Sub Command0_Click ...
    (microsoft.public.access.formscoding)
  • Re: Color Picking
    ... A Flex Grid Control will probably do what you want but you will need ... Private Type COLORSTRUC ... Private Sub Command0_Click ...
    (microsoft.public.access.formscoding)
  • Re: Color Picking
    ... A Flex Grid Control will probably do what you want but you will need ... Private Type COLORSTRUC ... Private Sub Command0_Click ...
    (microsoft.public.access.formscoding)
  • RE: Color Picking
    ... Public Function DialogColor(ctl As Control) As Long ... Private Sub CmdChooseBackColor_Click ... Private Type COLORSTRUC ... I have posted this question in the wrong group before (Form Design so ...
    (microsoft.public.access.formscoding)
  • Re: Color Picking
    ... Private Type COLORSTRUC ... Private Sub Command0_Click ... a way for them to pick a color from the color selection window in access ...
    (microsoft.public.access.formscoding)