Solved

Calculating in Access form

Posted on 2007-11-14
4
801 Views
Last Modified: 2013-11-29
Hi,

I am trying to set up a fairly simple database to record safety issues. In the entry form, I want the user to enter frequency (1-5) and severity (1-5), and have the form calculate the resulting score (multiplying the frequency and severity). This is, of course, easy to do in the reports, but the client would like to know if this can be calculated in the form as well. That way the user can see the score live as they enter the frequency and severity.

Is this possible, and if so, how?

Thanks,
Alex
0
Comment
Question by:bake_it
  • 2
4 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 20281794
In code behind the form of one of your combo boxes (air code, so you'll need to change a bunch of names)...

Private Sub SomeControlName_AfterUpdate()

'Bail if there is no value in the Frequency text box
If Nz(Me.Frequency, 0) = 0 then exit sub

'Bail if there is no value in the Severity text box
If Nz(Me.Severity, 0) = 0 then exit sub

Me.ResultingScore = CInt(Me.Frequency) * CInt(Me.Severity)

End Sub
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 20281826
{slight correction}

In code behind your Frequency and Severity boxes...

Private Sub Frequency_AfterUpdate
Call CalculateScore
End Sub

Private Sub Severity_AfterUpdate
Call CalculateScore
End Sub

... then as a separate sub ...

Private Sub CalculateScore()

'Bail if there is no value in the Frequency text box
If Nz(Me.Frequency, 0) = 0 then exit sub

'Bail if there is no value in the Severity text box
If Nz(Me.Severity, 0) = 0 then exit sub

Me.ResultingScore = CInt(Me.Frequency) * CInt(Me.Severity)

End Sub
0
 
LVL 15

Accepted Solution

by:
JimFive earned 500 total points
ID: 20292281
You can do it the same way you do on the report.
Create a textbox and set the value to "=Me.Frequency*Me.Severity"
0
 

Author Comment

by:bake_it
ID: 20300467
Thanks all who replied and sorry for the slow response. I didn't get a chance to work with this until today. JimFive, your solution did what I wanted and is about as simple as it gets! Thanks for your help.

The other solution (JimHorn) probably works too, but I do not have much experience working with coding. It wouldn't hurt for me to learn about that - any pointers toward a good starting resource would be appreciated. Thanks again.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

757 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