Division of existing fields to create new field

alexabraham

New Member
Joined
May 5, 2011
Messages
3
Hi Im new to Access and am now very stuck so any help would be fantastic.

i have put the following into the zoom box of an empty field of my query

Profit %: [profitvalbase]/[costvalbase]


this returns a "this expression is typed incorrectly or is too complex" message however and both are recognised fields in the table.

profit %: [profitvalbase]+[costvalbase]

returns a value without issue.

how can i divide one field by another to get a third field

Many Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Welcome to the Board!

Try getting rid of the space and percent sign in your alias.
 
Upvote 0
I just ran a quick query using this SQL statement and had no difficulty dividing one field by another.

Code:
SELECT Table1.Name, Table1.Sell, Table1.Cost, [Sell]-[Cost] AS Profit, [Profit]/[Cost] AS [Profit %]
FROM Table1;

Alan
 
Upvote 0
One of the "Best Practices" that many programmers will use is to avoid using spaces and special characters. They can sometimes wreak havoc when used in variables, object names, VBA, etc., unless handled properly (like enclosing them in brackets like Alan did).

Another thing to avoid is using key "reserved" words for object and variable names (like the names of functions, objects, and properties that Microsoft uses).
 
Upvote 0
thanks for the quick respones. it would apear that this was due to negative division (although the message didnt suggest this) so an IFF statement sorted this. :)
 
Upvote 0
it would apear that this was due to negative division
What do you mean? Dividing by a negative numbers is perfectly legal and shouldn't cause any issues.

Are both of your fields formatted as numeric fields? If you tried dividing by a Text field, I could see that causing strange messages/errors.
 
Upvote 0
well when i put the statement in the following format it works fine

=IIf([Divisor]=0,Null,[Dividend]/[Divisor])

i changed nothing else

so removing the posibility of division by zero allows it to return results.
 
Upvote 0
Yes, dividing by ZERO is not allowed, though dividing by NEGATIVE numbers is allowed (I presume you just misspoke in that post #5 and meant to say zero instead of negative).
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,109
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top