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, 3 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
-
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
22 seconds ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
6 hours, 31 minutes ago -
Sometimes I wonder about these bots
by
Susan Bradley
2 hours, 48 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
19 hours, 28 minutes ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
20 hours, 28 minutes ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
19 hours, 53 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
16 hours, 23 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
23 hours, 10 minutes ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
23 hours, 11 minutes ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
11 hours, 45 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
1 day, 7 hours ago -
0Patch, where to begin
by
cassel23
1 day, 1 hour ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
1 day, 20 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
1 day, 8 hours ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
2 days, 5 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
1 day, 20 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
1 day, 7 hours ago -
Installer program can’t read my registry
by
Peobody
24 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
1 day, 18 hours ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
2 days, 1 hour ago -
False error message from eMClient
by
WSSebastian42
2 days, 16 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
3 days, 1 hour ago -
Office 2021 Perpetual for Mac
by
rebop2020
3 days, 2 hours ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
29 minutes ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
3 days, 6 hours ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
13 hours, 51 minutes ago -
Outdated Laptop
by
jdamkeene
3 days, 11 hours ago -
Updating Keepass2Android
by
CBFPD-Chief115
3 days, 17 hours ago -
Another big Microsoft layoff
by
Charlie
3 days, 16 hours ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
19 hours, 5 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.