Results 1 to 9 of 9
  1. #1
    CTdbdev is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2014
    Posts
    12

    Arithmetic not correct when lookups are part of expression


    Hello,

    Running into an error here I'm not quite figuring out and can't find anything on this subject. In my table of products, in particular, I have a column for it's product code, vendor cost, product option lookup cells (which just reference another selected product and it's vendor cost), and a total cost column. In the total cost column I have an expression for example of =([vendcost] + [prodopt1] + [prodopt2]).

    The problem is, I can't get it to use the cost of the selected product option cells, but rather it always defaults to use the ID number in the math. I've moved the columns around so the cost column was the far left in the lookup cells, but that doesn't work. Ideally the value shown would be the product code, but it's cost would be used for the math. So now that I'm writing this I'm thinking if that could be written into the expression that would correct the error? Or am I tackling this the wrong way?

    Regards,
    Alex

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    It appears that

    a) you have not normalized your table(s)
    b) are including calculations/totals in your table. Better to do these via query when needed.

    Suggest you tell us what the database is about in plain English.
    Last edited by June7; 07-30-2014 at 05:54 PM.

  3. #3
    CTdbdev is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2014
    Posts
    12
    The thing is, I don't have multiple tables for this function. Everything is happening within just the one products table. I tried a new approach. In the product page form, I added a combo box that's referencing ID, Product code, and vendor cost. The selected value from the combo box is then stored in table column named prodopt1,2,etc. I edited the combo box so the vendor cost column is on the far left, since only the far left value is what only ever gets stored in the record cell. Now back in the table, it's only the vendor cost displayed, so the total cost column now adds right. Yes, I'm having math done and stored in the table this way. Is this solution described not the way to do things?

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    I suspect you have encountered one of the pitfalls of using lookups in tables. The consensus amongst the experts is that they are an abomination, to be avoided for reasons you have found.

    My suggestion would be to replace those with numeric pointers to the other records, and then use queries to calculate and display results.

    John

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by John_G View Post

    ...The consensus amongst the experts is that they are an abomination, to be avoided...
    And here's why:

    http://mvps.org/access/lookupfields.htm

    Linq ;0)>

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Re: post #3

    You don't need multiple tables. A query can contain the same table more than once - it adds _1, _2.... to the tables names, and you can create the joins as you would with any two tables. You do have to be a bit careful about which occurance you are referring to in expressions.

    As to keeping calculated results in the tables, you really shouldn't - that's what queries are for.

    HTH

    John

  7. #7
    CTdbdev is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2014
    Posts
    12
    Ok, I reworked things steering away from lookups. I made a query that lists the products and their cost. In the product report there are a couple combo boxes that reference that query. In the combo box wizard I selected to save the costs to the applicable columns in the original table for each product. That's all working correctly. If I'm executing this correctly from the feedback today...

    From my research, I saw that you don't need to/or shouldn't include the ID in the query. Is this correct? I only have the products and their cost in the query. It seems each product is remembering which item I selected as when I go back to a particular item, the combo boxes do display the correct values.

    Lastly, so if I shouldn't store calculated results in a table, and should by query, is another equally proper way to just have a non editable text box in my report and write an expression that does the calculation control it?

    Regards,
    Alex

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Whether or not ID should be included in combobox query depends on whether or not the ID is saved as foreign key. If it is not saved as FK then it doesn't need to exist at all.

    Calc in query usually preferable but calc in textbox acceptable.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    CTdbdev is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2014
    Posts
    12
    Great! Thanks!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 07-27-2014, 11:39 PM
  2. Use or not Use Multivalued Lookups
    By bradjake8 in forum Access
    Replies: 1
    Last Post: 08-05-2013, 05:05 PM
  3. Arithmetic with Access
    By Broxi in forum Access
    Replies: 1
    Last Post: 07-28-2013, 07:57 AM
  4. How Can export Large table part by part
    By shabar in forum Import/Export Data
    Replies: 2
    Last Post: 02-04-2013, 06:29 AM
  5. Replies: 9
    Last Post: 06-26-2011, 09:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums