I’m not an Access programmer but I need to create a database.
In this database there are 3 fields (Likelihood, Consequence, and Total Risk Exposure). I’m supposed to multiply the values of Likelihood and Consequence and place the sum in Total Risk Exposure. Depending on the sum I’m also supposed to change the color of Total Risk Exposure to either Green, Yellow, or Red. I’ve been told I need to do this as an After Update Event on both Likelihood and Consequence. Can anyone help me?
Thanks in advance.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Event Procedure Code (Access 2000)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Event Procedure Code (Access 2000)
- This topic has 9 replies, 3 voices, and was last updated 19 years, 4 months ago.
AuthorTopicWSdm19134
AskWoody LoungerJanuary 24, 2006 at 8:54 pm #428661Viewing 2 reply threadsAuthorReplies-
WSHansV
AskWoody Lounger -
WSdm19134
AskWoody Lounger -
WSHansV
AskWoody LoungerJanuary 24, 2006 at 9:17 pm #996343The “standard” approach is not to store a calculated field in a table, since it is derived information. Instead, create a query based on the table, and add a calculated column. The column will be up-to-date each time the query is opened, and the query can be used as record source for forms and reports.
To create such a column, enter the following in the first blank column in the query grid:Total Risk Exposure: [Likelihood]*[Consequence]
If you really need to store the calculated field in the table, you must create some code in the form based on the table that is used to enter/edit records.
Open the form in design view.
Select the text box bound to the Likelihood field. I’ll assume it is named Likelihood.
Activate the Event tab of the Properties window.
Click in the After Update event.
Select [Event Procedure] from the dropdown list.
Click the builder button … to the right of the dropdown arrow.
Complete the code so that it looks like this:Private Sub Likelihood_AfterUpdate()
Is IsNull(Me.Likelihood) Or IsNull(Me.Consequence) Then
Me.[Total Risk Exposure] = Null
Else
Me.[Total Risk Exposure] = [Likelihood] * [Consequence]
End If
End SubSwitch back to Access.
Repeat the above for the text box bound to the Consequence field. (The procedure will be named Consequence_AfterUpdate, of course) -
WSHansV
AskWoody Lounger -
WSdm19134
AskWoody Lounger
-
-
-
WSgellwood
AskWoody LoungerJanuary 24, 2006 at 9:24 pm #996349You’ll also need to create a procedure to change colours for the text of Total Exposure. You’ll need to do this everytime you change either Likelihood or Consequence PLUS everytime you move from one record to another. Since this code will have to go into 3 places, it’s better to create a separate sub routine or function and then call it from the Form’s Current event (which occurs when you move from one record to another), and the AfterUpdate events of Likelihood and Consequence.
You need to co into the Code behind the form and put this:
Private Sub Form_Current()
Call ChangeExposureColor
End SubPrivate Sub Likelihood_AfterUpdate()
Call ChangeExposureColor
End SubPrivate Sub Consequence_AfterUpdate()
Call ChangeExposureColor
End SubSub ChangeExposureColor()
Select Case Me.Exposure
Case 1 To 5
Me.Exposure.ForeColor = 8453888 ‘green
Case 6 To 10
Me.Exposure.ForeColor = 65535 ‘yellow
Case Is > 10
Me.Exposure.ForeColor = 255 ‘red
End Select
End Sub -
WSdm19134
AskWoody Lounger -
WSdm19134
AskWoody LoungerJanuary 25, 2006 at 4:26 pm #996543Gwenda,
Your code is great, thanks.
Is there a way to be more specific about the backcolor change. When I start a new record the color from the previous record is still there. I assumed it would reset to white till new numbers were entered in Likelihood and COnsequence.
Also, Is there a way to be more specific about the cases? 1*5 =5 is yellow but 5*1=5 is green. I’m dealing with a 5X5 Risk Matrix so it makes a difference what order you do the math. It needs to always be likelihood * consequence.
5 GYRRR
4 GYYRR
3 GYYYR
2 GGGYY
1 GGGGY
1 2 3 4 5 -
WSHansV
AskWoody LoungerJanuary 25, 2006 at 4:39 pm #996544Try this:
Sub ChangeExposureColor()
If IsNull(Me.Likelihood) Or IsNull(Me.Consequence) Then
Me.Exposure.ForeColor = vbBlack
Exit Sub
End If
Select Case 10 * Me.Likelihood + Me.Consequence
Case 11 To 14, 21 To 23, 31, 41, 51
Me.Exposure.ForeColor = vbGreen
Case 15, 24 To 25, 32 To 34, 42 to 43, 52
Me.Exposure.ForeColor = vbYellow
Case Else
Me.Exposure.ForeColor = vbRed
End Select
End Sub
-
-
Viewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Cell Phone vs. Traditional Touchtone Phone over POTS
by
280park
4 hours, 32 minutes ago -
Lost access to all my networked drives (shares) listed in My Computer
by
lwerman
4 hours, 23 minutes ago -
Set default size for pasted photo to word
by
Cyn
10 hours, 25 minutes ago -
Dedoimedo tries 24H2…
by
Cybertooth
5 hours, 27 minutes ago -
Windows 11 Insider Preview build 27871 released to Canary
by
joep517
1 day, 9 hours ago -
Windows 11 ad from Campaign Manager in Windows 10
by
Jim McKenna
1 day, 6 hours ago -
Small desktops
by
Susan Bradley
3 minutes ago -
Totally disable Bitlocker
by
CWBillow
2 hours, 57 minutes ago -
Phishers extract Millions from HMRC accounts..
by
Microfix
1 day, 6 hours ago -
Windows 10 22H2 Update today (5 June) says up-to-date but last was 2025-04
by
Alan_uk
2 days, 13 hours ago -
Thoughts on Malwarebytes Scam Guard for Mobile?
by
opti1
8 hours, 5 minutes ago -
Mystical Desktop
by
CWBillow
2 days, 16 hours ago -
Meta and Yandex secretly tracked billions of Android users
by
Alex5723
1 day, 21 hours ago -
MS-DEFCON 2: Do you need that update?
by
Susan Bradley
13 hours, 53 minutes ago -
CD/DVD drive is no longer recognized
by
WSCape Sand
3 days, 7 hours ago -
Windows 11 24H2 Default Apps stuck on Edge and Adobe Photoshop
by
MikeBravo
3 days, 10 hours ago -
North Face and Cartier customer data stolen in cyber attacks
by
Alex5723
3 days, 8 hours ago -
What is wrong with simple approach?
by
WSSpoke36
1 day, 6 hours ago -
Microsoft-Backed Builder.ai Set for Bankruptcy After Cash Seized
by
Alex5723
3 days, 20 hours ago -
Location, location, location
by
Susan Bradley
2 days, 10 hours ago -
Cannot get a task to run a restore point
by
CWBillow
3 days, 21 hours ago -
Frustrating search behavior with Outlook
by
MrJimPhelps
3 days, 12 hours ago -
June 2025 Office non-Security Updates
by
PKCano
4 days, 8 hours ago -
Secure Boot Update Fails after KB5058405 Installed
by
SteveIT
3 hours, 55 minutes ago -
Firefox Red Panda Fun Stuff
by
Lars220
4 days, 8 hours ago -
How start headers and page numbers on page 3?
by
Davidhs
4 days, 18 hours ago -
Attack on LexisNexis Risk Solutions exposes data on 300k +
by
Nibbled To Death By Ducks
3 days, 21 hours ago -
Windows 11 Insider Preview build 26200.5622 released to DEV
by
joep517
5 days, 3 hours ago -
Windows 11 Insider Preview build 26120.4230 (24H2) released to BETA
by
joep517
5 days, 3 hours ago -
MS Excel 2019 Now Prompts to Back Up With OneDrive
by
lmacri
4 days, 17 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.