Solved

After update to change form background

Posted on 2014-01-16
3
346 Views
Last Modified: 2014-01-16
After I update a field in a form, I would like it to change the color of the form. I already put code in that on the form for an "On Current" event. This code is working great. If possible I would like it to change if the field changes, not just when you click onto the form.

The code of the "On Current" of the form is this:

Private Sub Form_Current()

Select Case Me!cmOffice
     Case "Orange County"
      Me.Detail.BackColor = vbGreen
    Case "Riverside"
     Me.Detail.BackColor = vbBlue
     Case Else
      Me.Detail.BackColor = vbWhite
End Select

End Sub

WHat would the code be for the "After Update"?
0
Comment
Question by:cansevin
3 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39787243
If I understood you correctly, it would be the same thing.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39787247
use the same codes that you use in the Current event in the AfterUpdate event of control cmOffice
0
 
LVL 57
ID: 39787269
While it would be the same code in the AfterUpdate event of the control, you want to structure this a bit differently.

What you want is the code in a single place that you call from both locations.

So open up your form module, and at the top enter:

Sub SetFormBackGround()

End Sub will pop in.

Now take the code:

Select Case Me!cmOffice
     Case "Orange County"
      Me.Detail.BackColor = vbGreen
    Case "Riverside"
     Me.Detail.BackColor = vbBlue
     Case Else
      Me.Detail.BackColor = vbWhite
End Select


and paste it in between the two lines.

 Now go back to the OnCurrent and AfterUpdate of any controls involved and type:

  SetFormBackGround

 and remove the code that's already there.

 Now your code for setting the form background is in only one place, which makes it easier to maintain.

Jim.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question