Solved

Access - Calculate value of a field based on value of another in the same table

Posted on 2016-10-07
6
34 Views
Last Modified: 2016-10-10
Greetings Experts,

I have a table ('user') with the following structure:

ID (pk), Name, Age, EnctrCnt

I am trying to figure out a way (vba, query, view, new table, etc.) to calculate a weighted score based on the value of EnctrCnt.  

For the weights, if the user's encounter count is between 1-3 they get 3 points for each encounter, between 4-10 they get 5 points for each encounter, and for >10 they get 7 points for each encounter.  

I have tried doing this in a report and form using if statements.  The report didn't work and the form only worked if I clicked through each record using the On Load event.  I tried the On Open but nothing happened.

I have basic SQL and VBA knowledge so I am struggling with what is and is not allowed in Access.  

I am using Access 2013

Please let me know if you have any questions.
0
Comment
Question by:taskhill
  • 3
  • 2
6 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41834731
it would be more easier and dynamic for calculation if you have an encounter point table to store the points to be allocated for your range of encountered values
0
 

Author Comment

by:taskhill
ID: 41835183
I am fine with creating another table but I need assistance in how to calculate the values using SQL, VBA, or any other method.  Since the values are limitless I was leaning towards a loop but don't know how they are constructed in VBA or SQL. It would be easy for me to do in PHP but unfortunately  that is not an option because this is a system at work.
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41836375
once you have 2 tables you can construct the relevant SQL to generate the output you needed.

I think this can be done.

will you want to go with database option?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:taskhill
ID: 41836936
Yes a second table is fine with me.  I just need help creating the SQL to generate the results
0
 
LVL 2

Accepted Solution

by:
Antonio Salva Ripoll earned 500 total points
ID: 41837486
Hi.

If the ranges are fixed, you can use the IIF function, is easy and quick.

The SQL code could be:

SELECT ID, Name, Age, EnctrCnt, IIf([EnctrCnt]<=3,3,IIf([EnctrCnt]>3 And [EnctrCnt]<10,5,7)) AS Points
FROM [user];

Open in new window



Other way is to use the Partition function, but the ranges are determined by the function parameters.

You can find more info about the Partition Function here Partition function
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41837794
you can try this if you wish to use 2 tables do do mapping and calculation
28975123.accdb
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Query Missing Money orders... 6 73
How hide #Error in a form field 2 13
Best Approach MS Access 2013 3 23
SQL Query 3 0
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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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

16 Experts available now in Live!

Get 1:1 Help Now