Changing the BackColor of a form on the fly.

Brando

Enthusiastic Novice
Local time
Today, 12:23
Joined
Apr 4, 2006
Messages
100
Several command buttons on my switchboard open a search form. (The OnLoad event of the search form runs a filter with the matching product results displayed on a subform.) Depending on which switchboard button is selected, I want each one to set a different BackColor of the search form as it opens. A sample of the OnClick code I am currently using on one of the buttons is below. I get "Application-defined or Object-defined error" and the color does not change. I appreciate any help.

Private Sub cmdRed_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSearch"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Forms!frmSearch!cboProductType = "Saber"
Forms!frmSearch.BackColor = 255

End Sub
 
Several command buttons on my switchboard open a search form. (The OnLoad event of the search form runs a filter with the matching product results displayed on a subform.) Depending on which switchboard button is selected, I want each one to set a different BackColor of the search form as it opens. A sample of the OnClick code I am currently using on one of the buttons is below. I get "Application-defined or Object-defined error" and the color does not change. I appreciate any help.

Private Sub cmdRed_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSearch"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Forms!frmSearch!cboProductType = "Saber"
Forms!frmSearch.BackColor = 255

End Sub

My experience has been that the BackColor Attribute is not set for a form, but rather for objects on a form. Try setting the BackColor for the FormHeader Section, FormDetail Section, and FormFooter Section instead
 
The Rookie is right, Coach! You have to set the back color for each section of the form!
 
The Rookie is right, Coach! You have to set the back color for each section of the form!

I actually had the same problem in the beginning of my project, and wound up creating a function to do the update. It required me to go through over 40 Forms and rename all of the sections to be Exactly FormHeader, FormDetail, and FormFooter, but in the long run it was worth it, because a simple change to the database sets different background colors for production, Testing, and Development, and as long as we remain standardized, we can see the stage of each version of the program.
 
So this:

Forms!frmSearch.BackColor = 255

became this:

Forms!frmSearch.Detail.BackColor = 255

And it worked perfectly! Thank you!
 
So this:

Forms!frmSearch.BackColor = 255

became this:

Forms!frmSearch.Detail.BackColor = 255

And it worked perfectly! Thank you!

Remember that on some forms there might be a header and footer too.
 
Remember that on some forms there might be a header and footer too.

You are right. It is a pain in the arse.

With telemarketing data bases form appearance can mean a lot. If a different form means a 7% improvement then that is money in your pocket.

I found the best ways to address the problem are

1) You have several versions of the form and the appropriate form is the one opened.

2) I also use copyobject. That way a form opens with a "menu" of forms to be selected etc and etc. The form that is open is closed and copyobject is run and the form reopened and then Presto...looks like a new world:D
 

Users who are viewing this thread

Back
Top Bottom