Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

After update to change form background

Posted on 2014-01-16
3
Medium Priority
?
352 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 28

Accepted Solution

by:
MacroShadow earned 2000 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 58
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

782 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