Solved

Calculating in Access form

Posted on 2007-11-14
4
807 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 66

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 66

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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