user form colors

bigmac

Registered User.
Local time
Today, 08:51
Joined
Oct 5, 2008
Messages
302
hi all can you help please I have a front end form and would like to give the user the option to change the background color , what I need is on the click of a button to open the color picker so they can choose the coler they would like on the form and then the background change to the color they have picked , cheers :confused:
 
Because it is pretty complex to explain, here is a little example.
This uses the internal Access color picker isn't that cool ?

(Warning, sunglasses needed if you pick a bright color :cool:)
 

Attachments

Last edited:
hi grumm thank you for your response , this is great, I cannot follow the VBA to learn how to use it yet , but as I say this is great, one other question is it possible to save the color picked so when the user opens it again it keeps the color he/she has chosen
 
here is same code as mr.grum, but saves the color.
as a sample, create a form with a button, on the click event of you button

private sub button_click()
me.section(0).backcolor = colorpicker()
end sub
Code:
Option Compare Database
Option Explicit

#If Win64 Then
  
    Declare PtrSafe Sub ChooseColor Lib "msaccess.exe" Alias "#53" _
      (ByVal hwnd As Long, rgb As Long)
#Else
  
    Declare Sub ChooseColor Lib "msaccess.exe" Alias "#53" _
      (ByVal hwnd As Long, rgb As Long)
#End If

Public Function colorPicker() As Long
    Static lngColor As Long
    ChooseColor Application.hWndAccessApp, lngColor
    colorPicker = lngColor
End Function
 
hi arnelgp, tried this but did not save the color, it reverts back to original color, any ideas please
 
you mean the form, it reverts back to its normal color. have a table to save the value, ie:

tblFormColor
Fields:
FormName (short text)
BackColor (numeric long)

on your forms open event:
Code:
Private Sub Form_Open(Cancel As Integer)
    Dim lngBackColor As Long
    lngBackColor = Me.Section(0).BackColor
    Me.Section(0).BackColor = Nz(DLookup("BackColor", "tblFormColor", "FormName = '" & Me.Name & "'"), lngBackColor)
End Sub

on your button that changes the color of your form (click event):
Code:
Private Sub Command0_Click()
    Dim varForm As Variant
    Me.Section(0).BackColor = colorPicker()
    varForm = DLookup("BackColor", "tblFormColor", "FormName = '" & Me.Name & "'")
    If IsNull(varForm) Then
        DBEngine(0)(0).Execute "Insert Into tblFormColor (FormName, BackColor) " & _
            "SELECT '" & Me.Name & "', " & Me.Section(0).BackColor
    Else
        DBEngine(0)(0).Execute "Update tblFormColor Set BackColor = " & Me.Section(0).BackColor & " " & _
            "WHERE FormName = '" & Me.Name & "'"
    End If
End Sub
 
thanks arnelgp, this worked great, once again you have proved a great help to me and others
 
how would you apply this to change a button color on the same form and save it please
 
What version of access do you use ?
If you have 2010 or more version then you can use button.backcolor =
If not, you will need to make a label that replace the button. (There is a property to let it look like a button)
 
hi all , I think I've cracked it , I will post how I did it later after I have tested it fully , its a very long winded way but it seems to work.
 

Users who are viewing this thread

Back
Top Bottom