Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 27th, 2010, 01:05 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default RunSQL Update with Set

Howdy,

Getting an error 3144. incorrect syntax, but can't figure what is wrong.

I have 2 tables with identical columns. Table Names = tblEID and tblWT_Temp

I want to update the TermDate column in tblEID with the TermDate value in tblWT_Temp where EMPNUM in both match.

DoCmd.RunSQL Update tblEID
Set tblEID.TermDate = tblWT_Temp.TermDate
WHERE tblWT_Temp.EmpNum = tblEID.EmpNum

I don't want to have to enter a value via the parameter window when the statement runs either.

Any thoughts, greatly appreciated. You all have a good day.

bph
 
Old August 27th, 2010, 03:10 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Go to Access HELP, show TABLE OF CONTENTS, find JET SQL REFERENCE.

In that reference, find the UPDATE statement. I think it shows an example of multi-table update.

This machine I'm on doesn't have Access installed, but I know I've done it before on my home machine.

I think it *MIGHT* be as simple as
Code:
Update tblEID, tblWT_Temp
Set tblEID.TermDate = tblWT_Temp.TermDate 
WHERE tblWT_Temp.EmpNum = tblEID.EmpNum
But check the Access documentation to be sure.
 
Old August 27th, 2010, 03:55 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks OP. I'll check that out. It does seem to be real simple compared to theother stuff I have written.
 
Old September 1st, 2010, 04:11 PM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Default Hmm...

It seems like I can't even get your results of an error message with that syntax. It just prompts me for the values for each if the table's EmpNum fields. I'm using Access 2010, but I wrote it this way:

DoCmd.RunSQL ("UPDATE tblWT_Temp INNER JOIN tblEID ON tblWT_Temp.EmpNum = tblEID.EmpNum SET tblEID.TermDate = tblWT_Temp.TermDate;")

That seems to work for me, if I'm understanding what you want to do, and duplicating enough of your environment. Perhaps the Inner Join between the EmpNum records in the two tables helps Access figure it all out... HTH.

Blessings,

Duff
 
Old September 1st, 2010, 04:18 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Duff,

You are correct. That piece is working now, don't know why it failed me before.

Is there a way to not have the prompt for the values appears? If empnum matches, go update EID table and proceed with next row in tblWT_Temp, compare empnums and update accordingly. Cursor?

Thanks, bph
 
Old September 1st, 2010, 04:30 PM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi!

Mine didn't prompt once I did the INNER JOIN. I think it needs that. Did you re-do the SQL to have that relation, and it still prompts you?

Duff
The Following User Says Thank You to dabrowne For This Useful Post:
bph (September 1st, 2010)
 
Old September 1st, 2010, 05:13 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Smile

Hi Duff,

Awesome!!! Thanks so much for your help.

I put that in, and it ran perfect. Sorry I didn't follow that thought in your first post. I don't understand why it needed the INNER Join temrilogy, as I felt I was acheiving the same thing with the code I wrote.

Good stuff!

bph





Similar Threads
Thread Thread Starter Forum Replies Last Post
Docmd.RunSQL Armand elia BOOK: Access 2003 VBA Programmer's Reference 0 June 17th, 2009 03:47 PM
RunSql action rashi Access 1 September 28th, 2007 01:24 PM
Removing the MsgBox in DoCmd.RunSQL Update arfa Access 2 March 24th, 2006 08:05 PM
Programmatically set update for one Gridview recor wirerider ASP.NET 2.0 Basics 5 February 11th, 2006 01:00 PM
RunSQL (insert into... ) HELP Kevinsharrison Access VBA 5 April 26th, 2005 11:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.