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
-
How to get Microsoft Defender to honor Group Policy Setting (Awaiting moderation)
by
Ralph
1 hour, 43 minutes ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
2 hours, 22 minutes ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
3 hours, 28 minutes ago -
Disengage Bitlocker
by
CWBillow
4 hours, 52 minutes ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
5 hours, 28 minutes ago -
New Win 11 Pro Geekom Setup questions
by
Deo
7 hours, 12 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
12 hours, 43 minutes ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
12 hours, 44 minutes ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
16 hours, 40 minutes ago -
New PC transfer program recommendations?
by
DaveBoston
7 hours ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
20 hours, 44 minutes ago -
Windows 10 Build 19045.6029 (22H2) to Release Preview Channel
by
joep517
20 hours, 45 minutes ago -
Best tools for upgrading a Windows 10 to an 11
by
Susan Bradley
9 hours, 5 minutes ago -
The end of Windows 10 is approaching, consider Linux and LibreOffice
by
Alex5723
6 hours, 27 minutes ago -
Extended Windows Built-in Disk Cleanup Utility
by
bbearren
18 hours, 55 minutes ago -
Win 11 24H2 June 2025 Update breaks WIFI
by
dportenlanger
1 day, 15 hours ago -
Update from WinPro 10 v. 1511 on T460p?
by
CatoRenasci
13 hours, 38 minutes ago -
System Restore and Updates Paused
by
veteran
1 day, 18 hours ago -
Windows 10/11 clock app
by
Kathy Stevens
1 day, 5 hours ago -
Turn off right-click draw
by
Charles Billow
1 day, 21 hours ago -
Introducing ChromeOS M137 to The Stable Channel
by
Alex5723
2 days, 1 hour ago -
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
18 hours, 53 minutes ago -
Master patch listing for June 10, 2025
by
Susan Bradley
2 days, 2 hours ago -
Suggestions for New All in One Printer and a Photo Printer Windows 10
by
Win7and10
1 day, 5 hours ago -
Purchasing New Printer. Uninstall old Printer Software First?
by
Win7and10
2 days, 8 hours ago -
KB5060842 Issue (Minor)
by
AC641
20 hours, 43 minutes ago -
EchoLeak : Zero Click M365 Copilot leak sensitive information
by
Alex5723
2 days, 15 hours ago -
24H2 may not be offered June updates
by
Susan Bradley
1 day, 8 hours ago -
Acronis : Tracking Chaos RAT’s evolution (Windows, Linux)
by
Alex5723
3 days, 4 hours ago -
June 2025 updates are out
by
Susan Bradley
9 hours, 44 minutes 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.