CurrentDb.Execute update syntax problem

I am having a problem with vba code to update a table.

I have two tables     tblMatrix and tblMatirxTemp

When I fire the code, I want to update tblMatrix.Hours with the value tblMatrixTemp.Hours1  when the Employee, Customer and Project from both tables match and when tblMatrix.WeekEndingDate = tblMatrixTemp.WED1 match.


Using an update query, I can get the desired results.

UPDATE tblMatrix INNER JOIN tblMatrixTemp ON (tblMatrix.WeekEndingDate = tblMatrixTemp.WED1) AND (tblMatrix.HourType = tblMatrixTemp.HourType) AND (tblMatrix.Project = tblMatrixTemp.Project) AND (tblMatrix.Customer = tblMatrixTemp.Customer) AND (tblMatrix.Employee = tblMatrixTemp.Employee) SET tblMatrix.Hours = [tblMatrixTemp].[Hours1];

I do have a test to confirm that the record I want to update exists in the table.

I attached my vba code below
CurrentDb.Execute "UPDATE tblMatrix SET tblMatrix.Hour = tblMatrixTemp.Hours1 WHERE (tblMatrix.WeekEndingDate = tblMatrixTemp.WED1) AND (tblMatrix.HourType = tblMatrixTemp.HourType) AND (tblMatrix.Project = tblMatrixTemp.Project) AND (tblMatrix.Customer = tblMatrixTemp.Customer) AND (tblMatrix.Employee = tblMatrixTemp.Employee)"

Open in new window

LVL 1
ScamquistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jrdecarliCommented:
You SQL looks fine. I susepct that the issue is with differering field types between the two tables.
0
Patrick MatthewsCommented:
Your VBA is not using the right Jet SQL syntax.



CurrentDb.Execute "UPDATE tblMatrix INNER JOIN tblMatrixTemp ON " & _
    "(tblMatrix.WeekEndingDate = tblMatrixTemp.WED1) AND " & _
    "(tblMatrix.HourType = tblMatrixTemp.HourType) AND " & _
    "(tblMatrix.Project = tblMatrixTemp.Project) AND " & _
    "(tblMatrix.Customer = tblMatrixTemp.Customer) AND " & _
    "(tblMatrix.Employee = tblMatrixTemp.Employee) " & _
    "SET tblMatrix.Hours = [tblMatrixTemp].[Hours1];"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rey Obrero (Capricorn1)Commented:
use this formatting so you can easily the whole sql statement, using
debug.print  sql


Dim sql
sql = "UPDATE tblMatrix SET tblMatrix.Hour = tblMatrixTemp.Hours1"
sql = sql & " WHERE (tblMatrix.WeekEndingDate = tblMatrixTemp.WED1)"
sql = sql & " AND (tblMatrix.HourType = tblMatrixTemp.HourType)"
sql = sql & " AND (tblMatrix.Project = tblMatrixTemp.Project)"
sql = sql & " AND (tblMatrix.Customer = tblMatrixTemp.Customer)"
sql = sql & " AND (tblMatrix.Employee = tblMatrixTemp.Employee)"

debug.print sql

currentdb.execute sql

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

ScamquistAuthor Commented:
Capricorn1.
I get an error:

Run-time error '3061':
Too few parameters.  Expected 7.

and it hangs on
CurrentDb.Execute sql
0
Rey Obrero (Capricorn1)Commented:
check for the names of fields
0
Rey Obrero (Capricorn1)Commented:
hour is a reserved word, place it in []
Dim sql
sql = "UPDATE tblMatrix SET tblMatrix.[Hour] = tblMatrixTemp.Hours1"
sql = sql & " WHERE (tblMatrix.WeekEndingDate = tblMatrixTemp.WED1)"
sql = sql & " AND (tblMatrix.HourType = tblMatrixTemp.HourType)"
sql = sql & " AND (tblMatrix.Project = tblMatrixTemp.Project)"
sql = sql & " AND (tblMatrix.Customer = tblMatrixTemp.Customer)"
sql = sql & " AND (tblMatrix.Employee = tblMatrixTemp.Employee)"

debug.print sql

currentdb.execute sql

Open in new window

0
ScamquistAuthor Commented:
Capricorn1.
My mistake.  the field is Hours
I verified the spelling of all the field names.
Now the error is
Run-time error '3061':
Too few parameters.  Expected 6
and still hangs on CurrentDb.Execute sql.


I did try matthewspatrick solution and it works.  I would just like to know why this is failing.  I really looks like it should work, but I don't want to wast you time.  Thanks.

0
ScamquistAuthor Commented:
Thank you for the assist.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.