?
Solved

Calculating in Access form

Posted on 2007-11-14
4
Medium Priority
?
809 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 2000 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…
Suggested Courses

777 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