Changing forms background colour

TIbbs

Registered User.
Local time
Today, 17:52
Joined
Jun 3, 2008
Messages
60
I am trying to use VBA to create a procedure that sets the background Detail section of forms in white.
For ease of updating I want it to be stored in only one procedure, and for it to be called from other event procedures when the forms load.
Any idea how to implement it?
I can do this in macros, but I'm trying to gain more knowledge of VBA, so any ideas?

So far I have created this external module:

Sub AdjustColours()
Forms![SF SalesForm1].Detail.BackColor = vbWhite
End Sub


And called it by the OnLoad procedure on the SF Sales Form:
Private Sub Form_Load()
AdjustColours
End Sub

I'm trying to find out an easier coding option. Like CSS where it can be stored externally and called by a function on the body of the document.
 
Last edited:
Simple Software Solutions

Why not convert the macros to VBA and see what it is doing...
 
I'm trying to find out an easier coding option. Like CSS where it can be stored externally and called by a function on the body of the document.
[/COLOR][/I]
Looks like your solution you posted is roughly the easiest coding option. Now, for reusability, you might consider storing the color you want in a table and then using a DLookup to set the value. Then you can have a form that you can set the color to be and the code will set the value of the color in the table:


Code:
Sub AdjustColours()
Dim lngColor As Long
lngColor = DLookup("MyColorField","MyColorTable")
   Forms![SF SalesForm1].Detail.BackColor = lngColor
End Sub
Code:
Private Sub Form_Load()
   AdjustColours
End Sub

Or if you want to be able to set colors for various forms:
Code:
Sub AdjustColours(lng Color As Long)
lngColor = DLookup("MyColorField","MyColorTable")
   Forms![SF SalesForm1].Detail.BackColor = lngColor
End Sub
Code:
Private Sub Form_Load()
   AdjustColours vbWhite
End Sub

Or if stored in a table
Code:
Sub AdjustColours(lng Color As Long, strForm As String)
lngColor = DLookup("MyColorField","MyColorTable", "[FormNameField='" & strForm & "'")
   Forms![SF SalesForm1].Detail.BackColor = lngColor
End Sub
Code:
Private Sub Form_Load()
   AdjustColours vbWhite, Me.Name
End Sub
 
Thanks for the replies, so I was getting to the write solution all along, just overcomplicating myself.
This is my first professional database that my management asked me to create, I am still a bit in university mode. :rolleyes:
 

Users who are viewing this thread

Back
Top Bottom