PC Review


Reply
Thread Tools Rate Thread

Calculations, Queries and making it all come together in my table

 
 
Carla
Guest
Posts: n/a
 
      25th Nov 2009
hello,
I am trying to create a very simple database (I'm pretty new to Access). In
my main table it have a field call % Safe which is to show the results a
calculation. I understand I should create a query. I have two issues - one,
the calculation I created doesn't seem to work. I created a simple query
based on the fields in my main table, in the query field called % Safe, under
Criteria I entered = [# Safe]-[# Unsafe]/[# Safe]. now, I assumed it would
look at the data entered in the main table, perform the calculation and BAM
present me with answer in this field. Does not.

Other issue is how to create the relationship between the query and the main
table so that the correct calculation is showing with the correct data?

Hopefully this makes sense and hopefully you can help!
 
Reply With Quote
 
 
 
 
KARL DEWEY
Guest
Posts: n/a
 
      25th Nov 2009
Post the SQL of your query by opening in design view, click on VIEW - SQL
View, highlight all, copy, and paste in a post. Post some sample records
also.

--
Build a little, test a little.


"Carla" wrote:

> hello,
> I am trying to create a very simple database (I'm pretty new to Access). In
> my main table it have a field call % Safe which is to show the results a
> calculation. I understand I should create a query. I have two issues - one,
> the calculation I created doesn't seem to work. I created a simple query
> based on the fields in my main table, in the query field called % Safe, under
> Criteria I entered = [# Safe]-[# Unsafe]/[# Safe]. now, I assumed it would
> look at the data entered in the main table, perform the calculation and BAM
> present me with answer in this field. Does not.
>
> Other issue is how to create the relationship between the query and the main
> table so that the correct calculation is showing with the correct data?
>
> Hopefully this makes sense and hopefully you can help!

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      25th Nov 2009
On Wed, 25 Nov 2009 10:24:01 -0800, Carla <(E-Mail Removed)>
wrote:

>hello,
>I am trying to create a very simple database (I'm pretty new to Access). In
>my main table it have a field call % Safe which is to show the results a
>calculation. I understand I should create a query. I have two issues - one,
>the calculation I created doesn't seem to work. I created a simple query
>based on the fields in my main table, in the query field called % Safe, under
>Criteria I entered = [# Safe]-[# Unsafe]/[# Safe]. now, I assumed it would
>look at the data entered in the main table, perform the calculation and BAM
>present me with answer in this field. Does not.
>
>Other issue is how to create the relationship between the query and the main
>table so that the correct calculation is showing with the correct data?
>
>Hopefully this makes sense and hopefully you can help!


The % Safe field should SIMPLY NOT EXIST in your table. Since its value can be
calculated on demand, and since any value you store in a table field will be
wrong the moment a new record is added or the safe/unsafe status of a record
is changed, it's just a Bad Idea.

Secondly, you should not use special characters such as % or # in fieldnames.
They're legal (if you ALWAYS use [brackets]) but can cause real headaches and
hard-to-find bugs.

Thirdly, the Criteria line is used to provide *criteria* on a field to select
records matching the criteria. What you want is to create a new calculated
field in your Query.

Remove the % Safe field from your table (you REALLY don't want or need it!!!)
and create a query based on the table. In the query grid find a vacant Field
cell (the top row of the grid) and type your expression in it:

PctSafe: [# Safe]-[# Unsafe]/[# Safe]

Assuming that neither field will be NULL and that # Safe will never be 0, this
should do the calculation for you. You can then base a Form and/or Report on
this query to display the PctSafe value.
--

John W. Vinson [MVP]
 
Reply With Quote
 
Carla
Guest
Posts: n/a
 
      25th Nov 2009
Thanks John.

I think I understand what you are telling me. I removed the field %safe
from my table and added the calculation into the query as you indicated.

It is returning the wrong answer though. When I put the data into an excel
spreadsheet and use the formula =(A2-B2)/A2, where A is the # Safe column and
B is the # Unsafe column, I get the result of 93.75% when using 32 Safe and 2
Unsafe. My query in Access gives me a result of 31.9375. Any suggestions?

Also I have to put the query into design view and hit the run button to
update when I add additional data. How do I make this happen automatically?

"John W. Vinson" wrote:

> On Wed, 25 Nov 2009 10:24:01 -0800, Carla <(E-Mail Removed)>
> wrote:
>
> >hello,
> >I am trying to create a very simple database (I'm pretty new to Access). In
> >my main table it have a field call % Safe which is to show the results a
> >calculation. I understand I should create a query. I have two issues - one,
> >the calculation I created doesn't seem to work. I created a simple query
> >based on the fields in my main table, in the query field called % Safe, under
> >Criteria I entered = [# Safe]-[# Unsafe]/[# Safe]. now, I assumed it would
> >look at the data entered in the main table, perform the calculation and BAM
> >present me with answer in this field. Does not.
> >
> >Other issue is how to create the relationship between the query and the main
> >table so that the correct calculation is showing with the correct data?
> >
> >Hopefully this makes sense and hopefully you can help!

>
> The % Safe field should SIMPLY NOT EXIST in your table. Since its value can be
> calculated on demand, and since any value you store in a table field will be
> wrong the moment a new record is added or the safe/unsafe status of a record
> is changed, it's just a Bad Idea.
>
> Secondly, you should not use special characters such as % or # in fieldnames.
> They're legal (if you ALWAYS use [brackets]) but can cause real headaches and
> hard-to-find bugs.
>
> Thirdly, the Criteria line is used to provide *criteria* on a field to select
> records matching the criteria. What you want is to create a new calculated
> field in your Query.
>
> Remove the % Safe field from your table (you REALLY don't want or need it!!!)
> and create a query based on the table. In the query grid find a vacant Field
> cell (the top row of the grid) and type your expression in it:
>
> PctSafe: [# Safe]-[# Unsafe]/[# Safe]
>
> Assuming that neither field will be NULL and that # Safe will never be 0, this
> should do the calculation for you. You can then base a Form and/or Report on
> this query to display the PctSafe value.
> --
>
> John W. Vinson [MVP]
> .
>

 
Reply With Quote
 
TedMi
Guest
Posts: n/a
 
      27th Nov 2009
You need to wrap the subtraction in parens, just like you do in Excel:
PctSafe: ([# Safe]-[# Unsafe])/[# Safe]
-TedMi

"Carla" <(E-Mail Removed)> wrote in message
news:7842487A-E376-4EE9-B5B8-(E-Mail Removed)...
> Thanks John.
>
> I think I understand what you are telling me. I removed the field %safe
> from my table and added the calculation into the query as you indicated.
>
> It is returning the wrong answer though. When I put the data into an
> excel
> spreadsheet and use the formula =(A2-B2)/A2, where A is the # Safe column
> and
> B is the # Unsafe column, I get the result of 93.75% when using 32 Safe
> and 2
> Unsafe. My query in Access gives me a result of 31.9375. Any
> suggestions?
>
> Also I have to put the query into design view and hit the run button to
> update when I add additional data. How do I make this happen
> automatically?
>
> "John W. Vinson" wrote:
>
>> On Wed, 25 Nov 2009 10:24:01 -0800, Carla
>> <(E-Mail Removed)>
>> wrote:
>>
>> >hello,
>> >I am trying to create a very simple database (I'm pretty new to Access).
>> >In
>> >my main table it have a field call % Safe which is to show the results a
>> >calculation. I understand I should create a query. I have two issues -
>> >one,
>> >the calculation I created doesn't seem to work. I created a simple
>> >query
>> >based on the fields in my main table, in the query field called % Safe,
>> >under
>> >Criteria I entered = [# Safe]-[# Unsafe]/[# Safe]. now, I assumed it
>> >would
>> >look at the data entered in the main table, perform the calculation and
>> >BAM
>> >present me with answer in this field. Does not.
>> >
>> >Other issue is how to create the relationship between the query and the
>> >main
>> >table so that the correct calculation is showing with the correct data?
>> >
>> >Hopefully this makes sense and hopefully you can help!

>>
>> The % Safe field should SIMPLY NOT EXIST in your table. Since its value
>> can be
>> calculated on demand, and since any value you store in a table field will
>> be
>> wrong the moment a new record is added or the safe/unsafe status of a
>> record
>> is changed, it's just a Bad Idea.
>>
>> Secondly, you should not use special characters such as % or # in
>> fieldnames.
>> They're legal (if you ALWAYS use [brackets]) but can cause real headaches
>> and
>> hard-to-find bugs.
>>
>> Thirdly, the Criteria line is used to provide *criteria* on a field to
>> select
>> records matching the criteria. What you want is to create a new
>> calculated
>> field in your Query.
>>
>> Remove the % Safe field from your table (you REALLY don't want or need
>> it!!!)
>> and create a query based on the table. In the query grid find a vacant
>> Field
>> cell (the top row of the grid) and type your expression in it:
>>
>> PctSafe: [# Safe]-[# Unsafe]/[# Safe]
>>
>> Assuming that neither field will be NULL and that # Safe will never be 0,
>> this
>> should do the calculation for you. You can then base a Form and/or Report
>> on
>> this query to display the PctSafe value.
>> --
>>
>> John W. Vinson [MVP]
>> .
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Calculations, Queries and making it all come together in my ta Carla Microsoft Access Getting Started 1 25th Nov 2009 09:22 PM
Calculations in VBA or queries? =?Utf-8?B?Sm9lQTIwMDY=?= Microsoft Access Database Table Design 4 15th Feb 2007 03:05 AM
Calculations within queries.. zowow via AccessMonster.com Microsoft Access Queries 1 1st Dec 2006 02:35 PM
Calculations in Queries =?Utf-8?B?RXJpa2E=?= Microsoft Access Queries 4 28th Feb 2005 06:11 PM
Calculations in queries =?Utf-8?B?RmxpYw==?= Microsoft Access Queries 1 15th Mar 2004 05:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:50 PM.