[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Calculating in Access form

Posted on 2007-11-14
4
Medium Priority
?
813 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

649 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