Results 1 to 6 of 6
  1. #1
    kskelly is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    4

    Key field could refer to multiple tables in SQL statement

    This is the error:

    Click image for larger version. 

Name:	sql.jpg 
Views:	14 
Size:	19.6 KB 
ID:	21223


    Works in one query but not this one. Why?

    This is the query in question:



    Click image for larger version. 

Name:	SnipImage (2).JPG 
Views:	14 
Size:	60.0 KB 
ID:	21224


    Notice that the table "SCALEHOU" is specified.
    Last edited by kskelly; 07-08-2015 at 02:38 PM. Reason: additional info for clarity

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Can you switch your query to SQL View and post the code here, so we can see your entire query?

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Date and Day are reserved words (they are both intrinsic functions). Should not use reserved words as names.

    Post SQL statements of both queries.
    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.

  4. #4
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    sounds like you are specifying [Date] somewhere (criteria? field not shown?) and not specifying the table (e.g. [SCALEHOU].[Date]). [Date] is in both tables, so access needs to know which. Or it could be confused because Date is a reserved word

  5. #5
    kskelly is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    4
    Here is the SQL statement:

    OU.[X2 start 239], SCALEHOU.[Shift change 139], SCALEHOU.[Shift change 239], SCALEHOU.[X3 end 139], SCALEHOU.[X3 end 239], [Shift change 139]-[X2 start 139] AS [X2 139 total], [Shift change 239]-[X2 start 239] AS [X2 239 total], [X3 end 139]-[Shift change 139] AS [X3 139 total], [X3 end 239]-[Shift change 239] AS [X3 239 total], ([Shift change 139]-[X2 start 139])+([Shift change 239]-[X2 start 239]) AS [X2 total], ([X3 end 139]-[Shift change 139])+([X3 end 239]-[Shift change 239]) AS [X3 total], [X2 total]+[X3 total] AS [Belt scale total], [X2 139 total]+[X3 139 total] AS [139 total], [X2 239 total]+[X3 239 total] AS [239 total], IIf((([239 total]+0.0001)/([139 total]+0.0001))-1>200,0,(([239 total]+0.0001)/([139 total]+0.0001))-1) AS [% diff], [X2 start 139]-[Day 139] AS [Day 139 total], [X2 start 239]-[Day 239] AS [Day 239 total], SCALEHOU.[Day 139], SCALEHOU.[Day 239], IIf([SCALEHOU]![INVBDAY]+[SCALEHOU]![MSWRECVD]-[SCALEHOU]![INVBNDAY]+[SCALEHOU]![FERRUSRESMSW]-[SCALEHOU]![msw out]<=0,0,[SCALEHOU]![INVBDAY]+[SCALEHOU]![MSWRECVD]-[SCALEHOU]![INVBNDAY]+[SCALEHOU]![FERRUSRESMSW]-[SCALEHOU]![msw out]) AS MSWPROCESSED, ([Belt scale total]-[MSWPROCESSED]) AS Diff, [139 total]/[LINE1 RUN HOURS] AS [LINE1 TPH], (([X2LINE2RUN]+[X3LINE2RUN])/60)+0.01 AS [LINE2 RUN HOURS], (([X2LINE1RUN]+[X3LINE1RUN])/60)+0.01 AS [LINE1 RUN HOURS], [239 total]/[LINE2 RUN HOURS] AS [LINE2 TPH], SCALEHOU.X2LINE1RUN, SCALEHOU.X3LINE1RUN, SCALEHOU.X2LINE2RUN, SCALEHOU.X3LINE2RUN
    FROM SCALEHOU INNER JOIN QRYCALCHOURS ON SCALEHOU.DATE = QRYCALCHOURS.DATE

    I suspect the problem in in the red?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That is not a complete SQL statement. I don't see SELECT of FROM or WHERE clauses. Joining on date/time type fields should not be an issue.

    Advise no spaces or special characters/punctuation (underscore is exception) in naming convention. No reserved words as names. Title case is easier to read. Better would be X2Line1Run or X2_Line1_Run.
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-06-2013, 03:03 PM
  2. Replies: 4
    Last Post: 02-16-2012, 05:23 PM
  3. Replies: 10
    Last Post: 08-08-2011, 01:55 PM
  4. SQL statement from multiple tables
    By Backpacker in forum Queries
    Replies: 5
    Last Post: 06-17-2011, 11:22 PM
  5. coding to refer to multiple checkboxes and labels
    By tammiep in forum Programming
    Replies: 2
    Last Post: 11-29-2010, 01:43 AM

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