Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    moocho992345 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    10

    Expression data selection trouble

    I have this expression:


    [Tickets Sold] * [Ticket Price]
    in the TotalCash column

    from this table.
    Click image for larger version. 

Name:	TicketEventTable.png 
Views:	9 
Size:	9.3 KB 
ID:	24273

    The expression is supposed to take the ticket price times the tickets sold to get a total, But as you can see the math is wrong. Ticket price is linked to the following table table. The connection is ID>TicketPrice. It's multiplying by the ID of the ticket Price. I need to find a way to get the math to work correctly.
    Click image for larger version. 

Name:	ticket price.png 
Views:	9 
Size:	6.8 KB 
ID:	24274
    The ticket price field is a combo box.

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Can you post the SQL code for your query (switch your query to "SQL View" and copy and paste the code here)?

  3. #3
    moocho992345 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    10
    The expression is in the table design, not a query. I don't think there is an SQL view option for tables.

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I know that newer versions of Access allow calculated fields in Tables, but I would recommend against using them (as most programmers do). For one thing, it is not compatible with any other database program (like SQL), so if you ever needed to upgrade to SQL, you would have issues.

    I would recommend doing all calculations like this in a calculated field in a query. There is no need to store anything at the table level which can easily be calculated in a query.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    calculated fields in tables can only reference fields in that record, so sounds like you have committed the second sin of table design and used a lookup for your prices thinking this is a way round it. You see a price so you think it is a price - it isn't - it is a looked up price - your calculation is multiplying quantity x the priceID.

    Take JoeM's advice. Don't use calculated (or lookup) fields so you can see what you actually have as data, not what is presented.

  6. #6
    moocho992345 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    10
    I made a query with the calculations. Here is the SQL:
    Code:
    SELECT TicketEventWithMyData.TEID, TicketEventWithMyData.SellerName, TicketEventWithMyData.EventName, TicketEventWithMyData.EventDate, TicketEventWithMyData.PatronType, TicketEventWithMyData.RollColor, TicketEventWithMyData.TicketPrice, TicketEventWithMyData.RollStartNum, TicketEventWithMyData.RollEndNum, TicketEventWithMyData.StartCash, [RollEndNum]-[RollStartNum] AS TicketsSold, [TicketsSold]*[TicketPrice] AS TotalCashFROM TicketEventWithMyData;

  7. #7
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    So, does it work now?

    If not, it may not like that you are using aliases for fields you just calculated in other calculations in the same query. If that is the case, replace this:
    Code:
    [TicketsSold]*[TicketPrice] AS TotalCash
    with this:
    Code:
    ([RollEndNum]-[RollStartNum])*[TicketPrice] AS TotalCash

  8. #8
    moocho992345 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    10
    I replaced it. The wierdest thing happened though. It didn't change. It should pull the calculated value from ([RollEndNum]-[RollStartNum]). I get this:
    Click image for larger version. 

Name:	Newpics.png 
Views:	8 
Size:	9.2 KB 
ID:	24275
    The ticketsSold is corect, but the TotalCash still used the ID numbers. What???

  9. #9
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Wait, I think I know what is going on. You said that the Ticket Price is a combo box field from another table, right?
    Take a look at the Properties of this field in your table. On the Lookup tab, is the Bound Column set to 1 or 2?
    If your price is the 2nd field in your Row Source (ID field is 1, TicketPrice is 2), then the Bound Column needs to be set to 2.

    Note that in a LOOKUP table where all your values have to be unique, there usually isn't a need for an ID field. If the LOOKUP table only has one field, then this won't ever be an issue. If you do need/want an ID field for some reason, sometimes they are easier to handle if you make the ID field the last field instead of the first. That will also avoid this issue.

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    as identified in post #5

  11. #11
    moocho992345 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    10
    The bound column just seems to change the appearance of the data. When the bound column is 1, it shows what its actually multiplying by, the ID. When the bound column is 2, it shows the ticket price, but it's still multiplying by the ID.

  12. #12
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    How about getting rid of the ID field in that table altogether (or at least make it the last field in your table instead of the first)?
    As I mentioned in my previous post, it may not even be necessary.

  13. #13
    moocho992345 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    10
    Switching the the ID to the last field just switched it around so that if the bound column is 1, it show the ticket price and If it's 2, it shows the ID. The value it's multiplying by doesn't seem to change. I can't delete it because it's a primary key.

  14. #14
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Make the Price key the Primary Key, and then you should be able to delete it.

  15. #15
    moocho992345 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    10
    Alright I tried making the price key the primary key and It screws up the combo box, so I changed the ID, the primary key into a currency. That allowed me to enter numbers like 2.5 and 3.5 in so I could match the ID to the price. The only issue with this however is that when you go to use the combo box to select a non whole number like 2.5, it changes it into 2. I wish I could same the same happened for 3.5, but it rounded that up to 4.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Expression trouble
    By Confu in forum Access
    Replies: 4
    Last Post: 07-24-2015, 10:52 AM
  2. Replies: 3
    Last Post: 03-26-2013, 08:51 AM
  3. trouble understanding expression
    By mejia.j88 in forum Queries
    Replies: 4
    Last Post: 02-01-2012, 03:00 PM
  4. Trouble with Expression
    By kctxucop08 in forum Access
    Replies: 1
    Last Post: 07-14-2011, 01:55 AM
  5. Expression trouble
    By ROB in forum Access
    Replies: 2
    Last Post: 06-08-2010, 09:36 AM

Tags for this Thread

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