Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run an Insert query into another database from code

Status
Not open for further replies.

kbdci

Programmer
Jul 16, 2002
33
US
I want to run an Insert query to insert records from one database into a different database using VBA code in Access 2007. I have set each database using the names WorkingDB as the source database and ActiveDB as the target database. The SQL is something like this:

strSQL4 = "INSERT INTO content ( contentid, contentname ) IN " & ActiveDB & "SELECT content.contentid, content.contentname FROM content, tblLkpSaveUpdatedDate IN” WorkingDB & “WHERE [tblLkpSaveUpdatedDate]![TimeUpdated] < [content]![createDate]"

Unfortunately, this doesn’t work. When I try to compile the code I get an error on the “ActiveDB” that says it is a type mismatch.

Is it possible to run this kind of query from code? If so, how can I do it?

Thanks.
 
You want something on the lines of:

Code:
strSQL4 = "INSERT INTO content ( contentid, contentname ) " _
& "SELECT content.contentid, content.contentname " _
& "FROM content, tblLkpSaveUpdatedDate IN '" & workingdb _
& "' WHERE [tblLkpSaveUpdatedDate]![TimeUpdated] < [content]![createDate]"

Set db = CurrentDb  ''Activedb
db.Execute strSQL4, dbFailOnError

Though I suspect you want a join other than Cartesian, probably Inner Join.

 
you want a join other than Cartesian
The posted join is called a theta join.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top