Solved

Calculating in Access form

Posted on 2007-11-14
4
805 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
On Key Down Access 2010 6 41
set focus to tabbed sub form 10 39
ADODB problem 20 37
Event that fires when moving from record to the next on a subform 3 11
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

792 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