Color Picking

S

Silvio

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)
 
S

Silvio

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 ***********
 
D

Damon Heron

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
 
S

Silvio

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.
 
P

Petr Danes

I don't think you can do that, at least not the way you want. Color
selection is formatting, not data, and formatting is the same for all
displayed detail instances of a continuous form.

Conditional formatting could do the trick, provided that you have no more
than three choices, since that's the limit there.

If you have more than three color choices and you have Access 2007, you
might be able to get it to work with rich text formatting. I've never used
it, but it's the only thing I know of that has enough possibilities.

Petr



Silvio said:
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 said:
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
 
D

Damon Heron

Yes, I noticed later that you said continuous form view, I have since looked
at it and you are correct in that if you are showing more than one record,
it appears to exhibit that behaviour. I don't know of any elegant solution
for this in continuous forms view. You could add a form header and footer,
and just move the textbox up to the header, and when the record is selected,
it would show the current color. Other than that, I am afraid I can't help
you.

Damon

Silvio said:
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 said:
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
 
P

Peter Hibbs

Silvio,

A Flex Grid Control will probably do what you want but you will need
to write a bit of VBA code, have a look at my Flex Grid Demo program
for some examples.

You would replace the Continuous form with a Flex Grid control and
then you can have as many colours as you like.

Go to http://www.rogersaccesslibrary.com/forum/forum_posts.asp?TID=180

HTH

Peter Hibbs.



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 said:
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
 
S

Silvio

Thank you both for your help. I will see which way to go...

Peter Hibbs said:
Silvio,

A Flex Grid Control will probably do what you want but you will need
to write a bit of VBA code, have a look at my Flex Grid Demo program
for some examples.

You would replace the Continuous form with a Flex Grid control and
then you can have as many colours as you like.

Go to http://www.rogersaccesslibrary.com/forum/forum_posts.asp?TID=180

HTH

Peter Hibbs.



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 said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top