954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Changing Color of a Form, Using A Function in Office 2010

I'm still pretty new to this and I need some help. Here's the situation. First the user opens a form to select which database (one of 3) they are working in. Then they will be using several forms. The same set of forms are always used no matter which database they're in. My boss has the following requirement - if they choose the NB database, we want all the forms they open to be Blue. If they choose database IB, all the forms they open should be Red, and for LB database, all forms they open will be Green. This is so it's very obvious to the user at all times which database they are working in to avoid mistakes. I want to make a function on the Form Selection form that will open all the forms in a certain color.

So lets say the user selects the NB database. This opens frmSelectNB, which gives them the list of forms they can open. Sorry if this sounds confusing. When they click the button on this page to open the form, I want a function on this form, that sets the color of the form they are opening. In other words, I can't use Me.detail.backcolor, because the function's on the page which opens the forms, not on the form that's being opened.
Button1 opens formItem, Button2 opens formExam, Button3 opens formReport, etc. Here's what I was thinking:

Public Sub SetColor(strFormName As String, StrColor As String)
'What do I put here to make this work?
End Sub

Private Sub Button1_Click()
dim strFormName as string
dim strColor as string

strFormName = "frmItem"
doCmd.OpenForm strFormName
strColor = RGB(79,129,189)

Call SetColor(strFormName, strColor)
End Sub

I know this is the basic format that I would normally use to set BackColor for the 3 form properties, but how do I pass variables into it? How can I modify it to work in my function?

Forms!frmItem.FormHeader.BackColor = RGB(79, 129, 189)
Forms!frmItem.FormDetail.BackColor = RGB(79, 129, 189)
Forms!frmItem.FormFooter.BackColor = RGB(79, 129, 189)

I also understand how to make the whole thing a string variable, like this, but I can't exactly execute it as a string.

strChangeHeader = "Forms!" & strFormName & ".FormHeader.BackColor = " & strColor

I also know there is a doCmd.SetProperty function, and it has something called acPropertyBackColor, but I have never used it and have no idea how it's used. I couldn't find any information on it that was helpful enough.

Which way should I do this and how is it done? Can someone please point me in the right direction here? I'm a bit lost. Thanks very much in advance.

dlindner999
Newbie Poster
2 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Okay, a couple of things.

First, your SetColor subroutine. The color variable you pass needs to be a long integer, not a string. Next, you can refer to your form in the Forms collection like so:

Public Sub SetColor(strFormName As String, StrColor As Long)
Forms(strFormName).Section(0).BackColor = StrColor
End Sub

Finally, you have to change the variable in the Click event to be a long integer:

Private Sub Button1_Click()
dim strFormName as string
dim strColor as Long

strFormName = "frmItem"
doCmd.OpenForm strFormName
strColor = RGB(79,129,189)

Call SetColor(strFormName, strColor)
End Sub

Hope that gives you what you need. Good luck!

BitBlt
Master Poster
711 posts since Feb 2011
Reputation Points: 367
Solved Threads: 109
 

That's what I needed, thank you very much!

dlindner999
Newbie Poster
2 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: