Results 1 to 6 of 6
  1. #1
    Deggsy is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    20

    Syntax Error in Query Expression

    Help! I have a query designed to compile a list of training events with a parameter prompt for the Region CMB (see below):


    SELECT Training_Events.Title, Training_Events.[Start Date], Training_Events.[Start Time], Training_Events.[End Time], Training_Events.Location, Training_Events.Description, Training_Events.Trainer, DLookUp("[Regional Operations Director Code]","Stores","[Cost Centre]=" & [Location]) AS Expr1
    FROM Training_Events
    WHERE (((DLookUp("[Regional Operations Director Code]","Stores","[Cost Centre]=" & [Location]))=[Forms]![Show_Reports]![Region_CMB]));
    There are two tables involved, Training Events and Stores (Design details below). The query expression was designed to take the appropriate region code from the Stores table, under the Regional Operations Director Code field. The query was attached to a report. Whether I run the query via the report or directly, I get the same syntax error message (see below) which appears to be related to the Cost Centre. Now, where do I begin to go to find the source of the error and correct it? Is it possible that it is new data in one of the tables which is incompatible with the rest?
    It seems to run the query (when I trigger it directly), but the error message still appears (in fact it seems to appear periodically after I click OK on it!)


    Click image for larger version. 

Name:	Stores Design.JPG 
Views:	11 
Size:	55.8 KB 
ID:	20893Click image for larger version. 

Name:	Training Events Design.JPG 
Views:	11 
Size:	42.1 KB 
ID:	20894Click image for larger version. 

Name:	Syntax Error.JPG 
Views:	11 
Size:	14.9 KB 
ID:	20896

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    For starters, I'd expect the two tables to be joined in the query rather than using DLookup() to get values from the second. The DLookup()'s will really slow the query down. Have you tried that?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Deggsy is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    20
    Quote Originally Posted by pbaldy View Post
    For starters, I'd expect the two tables to be joined in the query rather than using DLookup() to get values from the second. The DLookup()'s will really slow the query down. Have you tried that?
    That's a good idea - how would that look, given the information in the query (sorry, I'm not an expert and someone else created this nightmare of a database that other people are expecting me to sort out for them)

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Start a new query, add both tables to the grid. If the join line isn't already added, click and drag between the appropriate fields (the fields in your DLookup criteria). Then you can add fields from both tables to the field grid below.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Deggsy is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    20
    Quote Originally Posted by pbaldy View Post
    Start a new query, add both tables to the grid. If the join line isn't already added, click and drag between the appropriate fields (the fields in your DLookup criteria). Then you can add fields from both tables to the field grid below.
    Thanks, I'll give that a try, though I think the fields that should be joined are for some reason of different types, and I'm afraid to change them because they'll probably affect other queries, forms and whatnot. Still, that's my worry, not yours, thanks again for the advice :-)

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    No problem, post back if you're still stuck. There are ways around the data type problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 09-10-2014, 11:30 AM
  2. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  3. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. syntax in query expression #ERROR help!
    By manos39 in forum Queries
    Replies: 1
    Last Post: 02-26-2011, 12:21 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