If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Updating and adding records from one table to another

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-24-11, 16:41
howsle howsle is offline
Registered User
 
Join Date: Aug 2011
Posts: 3
Question Updating and adding records from one table to another

I am new to Access, but learning quickly. So, I need to update tables on a biweekly basis from .CSV files. I have the create table & delete table functions, but I am having problems with my update existing and adding programming. I know NO SQL, but am familiar with VBA. Can someone help?

Existing Table: tblProjExp
Temp table (.csv loads to): tblImportPE
Primary key field: IRBNet ID
Below is what I have that is not working

Private Sub updatPE_Click()
CurrentDb.Execute _
"UPDATE tblProjExp O INNER JOIN tblImportPE I ON O.IRBNetID = I.IRBNet ID " & _
"SET O.Board = I.Board, O.Title = I.Title, O.PI Name = I.PI Name, O.Sponsor = I.Sponsor, O.Keywords = I.Keywords, O.Internal Reference Number = I.Internal Reference Number, O.Submission ID = I.Submission ID, O.Board Reference Number = I. Board Reference Number, O.Submission Type = I.Submission Type, O.Submission Date = I.Submission Date, O.Review Type = I.Review Type, O.Action = I.Action, O.Effective Date = I.Effective Date, , O.Project Status = I.Project Status, O.Initial Approval Date = I.Initial Approval Date, O.Project Expiration Date = I Project Expiration Date, O.Days to Expiration = I.Days to Expiration", _
dbFailOnError

"INSERT INTO tblProjExp (IRBNetID, Board, Title, PI Name, Sponsor, Keywords, Internal Reference Number, Submission ID, Board Reference Number, Submission Type, Submission Date, Review Type, Action, Effective Date, Project Status, Initial Approval Date, Project Expiration Date, Days to Expiration") " & _
"SELECT I.Board, I.Title, I.PI Name, I.Sponsor, I.Keywords, I.Internal Reference Number, I.Submission ID, I.Board Reference Number, I.Submission Type, I.Submission Date, I.Review Type, I.Action, I.Effective Date, I.Project Status, I.Initial Approval Date, I.Project Expiration Date, I.Days to Expiration" & _
"FROM tblImport I LEFT JOIN tblProjExp O " & _
"ON I.IRBNet ID = O.IRBNetID" & _
"WHERE O.IRBNetID Is Null", _
dbFailOnError

End Sub
Reply With Quote
  #2 (permalink)  
Old 08-24-11, 17:22
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
What are the error code(s) and message(s)?
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 08-24-11, 17:31
howsle howsle is offline
Registered User
 
Join Date: Aug 2011
Posts: 3
RE:Updating and Adding Records from one

Quote:
Originally Posted by Sinndho View Post
What are the error code(s) and message(s)?
Compile error: Syntax error
Reply With Quote
  #4 (permalink)  
Old 08-24-11, 18:05
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
For starters, all of the fields with the inadvisable spaces in them have to be bracketed, like:

O.[PI Name]

I also see at least one instance of the period between table and field missing. I also see there won't be a space before the word WHERE in the second one. I personally would build a string variable and then execute it; much easier to debug.
__________________
Paul
Reply With Quote
  #5 (permalink)  
Old 08-25-11, 09:05
howsle howsle is offline
Registered User
 
Join Date: Aug 2011
Posts: 3
RE: Updating & String Variables

I am a novice at this, is there a good place (web) to learn more about string variables programming.
Reply With Quote
  #6 (permalink)  
Old 08-25-11, 12:10
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
In this instance there wouldn't be much to it:

Code:
Dim strSQL As String

strSQL = "UPDATE..."

CurrentDb.Execute strSQL
If/when you have trouble, that lets you add

Code:
Debug.Print strSQL
after the string is built, which prints out the finished SQL to the VBA Immediate window. If you don't spot the problem there you can copy/paste it into a blank query and try to run it, which will often give you a more descriptive error than you'll get in VBA.
__________________
Paul
Reply With Quote
Reply

Tags
update recordset, vba

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On