Solved

After update to change form background

Posted on 2014-01-16
3
344 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 26

Accepted Solution

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

Expert Comment

by:Rey Obrero
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now