Results 1 to 9 of 9
  1. #1
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067

    SQL Help

    I have a Query that I run in VBA for a recordset that I'm having a problem with. Here's the query

    Code:
    SELECT dbo_tbl_adv_source.advsource, dbo_tbl_Adv_type.Adv_Type, dbo_tbl_adv_schedule.adv_rundate 
    FROM dbo_tbl_adv_source 
    INNER JOIN dbo_tbl_adv_schedule ON dbo_tbl_adv_source.advsourceid = dbo_tbl_adv_schedule.adv_sourceid 
    INNER JOIN dbo_tbl_Adv_type ON dbo_tbl_adv_schedule.adv_TypeID = dbo_tbl_Adv_type.Adv_TypeID 
    WHERE dbo_tbl_adv_schedule.adv_schedid = 1;
    Everytime it runs I get a syntax error. I put it into Query Analyzer and get the same error. Take the query and put it into SQL Server change the dbo_ to dbo. and it works perfectly. I've looked at the query I don't see any syntax error. Data Structure is

    dbo_tbl_adv_source
    advsourceid autokey
    advsource text

    dbo_tbl_adv_type


    adv_typeID autokey
    adv_type text

    dbo_adv_schedule
    schedid autokey
    adv_sourceID numeric foreign key to dbo_tbl_adv_source
    adv_typeid numeric foreign key to dbo_tbl_adv_type
    adv_rundate date

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    Don't run it as vb, try it as a query. It can help you with the error.

  3. #3
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    As I stated in my original post I put the SQL into the query analyzer and got the same error.

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Recreate the query in Access from scratch. Make sure it works. Then copy the SQL to VBA.

  5. #5
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    Thanks aytee111 that worked don't know why I didn't think of that. Probably because that was the easiest way to fix it.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  7. #7
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    Here's the sql that works

    Code:
    SELECT dbo_tbl_Adv_Source.AdvSource, dbo_tbl_Adv_type.Adv_Type, dbo_tbl_Adv_Schedule.Adv_RunDate 
    FROM (dbo_tbl_Adv_Schedule INNER JOIN dbo_tbl_Adv_type ON dbo_tbl_Adv_Schedule.adv_TypeID = dbo_tbl_Adv_type.Adv_TypeID) 
    INNER JOIN dbo_tbl_Adv_Source ON dbo_tbl_Adv_Schedule.Adv_SourceID = dbo_tbl_Adv_Source.AdvSourceID 
    WHERE (((dbo_tbl_Adv_Schedule.Adv_SchedID) =  1)) 
    GROUP BY dbo_tbl_Adv_Source.AdvSource, dbo_tbl_Adv_type.Adv_Type, dbo_tbl_Adv_Schedule.Adv_RunDate;
    Other than adding the group by and reordering the From clause I don't really see much of a difference.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I think the key is the bracket
    Code:
    ....(dbo_tbl_Adv_Schedule INNER JOIN dbo_tbl_Adv_type ON 
    dbo_tbl_Adv_Schedule.adv_TypeID = dbo_tbl_Adv_type.Adv_TypeID) ....
    Glad you have it resolved.

  9. #9
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    Orange I think you're right. Thanks

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

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