We help IT Professionals succeed at work.
Get Started

Problems with DoCmd.RunSQL in Access 2003 and SQL 2008 database

Last Modified: 2012-05-11
I have a simple SQL statement that updates records in a table from records in the same table.  The SQL works fine in SQL 2008 Server Management Tool as a stored procedure.  When I try to run it via the DoCmd.RunSQL it gives me a runtime error 3075 with a message of a syntax error (missing operator).  I copy the exact string Access is creating and paste it into a SQL2008 script and it save it as a stored procedure and it executes perfectly.  

Obviously there is some limitations or differences between Access DoCmd.RunSQL and running a stored procedure directly in SQL 2008.  I am able to run other SQL commands but so far nothing with an INNER JOIN.

Here is the Code:
    DoCmd.SetWarnings False
    strSQL = "UPDATE  t1 " & _
             " SET     LaneIdx = t2.LaneIdx, " & _
             "         StyleIdx = t2.StyleIdx, " & _
             "         SizeIdx = t2.SizeIdx, " & _
             "         GradeIdx = t2.GradeIdx , " & _
             "         LabelIdx = t2.LabelIdx " & _
             " FROM    dbo_TblLaneCfgDet t1 " & _
             " INNER JOIN dbo_TblLaneCfgDet t2 on t2.LaneIdx = t1.LaneIdx " & _
             " AND t2.LaneCfgHdrIdx = " & OrigLaneCfgHdrIdx & _
             " WHERE   t1.LaneCfgHdrIdx = " & NewLaneCfgHdrIdx
    DoCmd.RunSQL strSQL

If someone can tell me how to fix the syntax so that it will work for Access that would work.  

If not, can someone show me the Access 2003 syntax to call a stored procedure from SQL 2008 including the connection logic:
proc:  usp_CopyLaneConfig
parm1: INT
parm2: INT

The stored procedure method is preferred, but I am having problems with the exact syntax from Acess 2003.  I call stored procedures in Visual 2008 C# without any problems, very straightforward syntax, but I am having problems in Access.  The help in Access 2003 is limited at best (at least for me).

Watch Question
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE