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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IINSERT syntax question

Status
Not open for further replies.

FinalPrime

Technical User
Jul 28, 2003
50
US
Hello,

MSND provides this synax at their Office Developer Center

INSERT INTO target [(field1[, field2[, …]])] [IN externaldatabase] SELECT [source.]field1[, field2[, …] FROM tableexpression

They say

"externaldatabase" is the path "to" an external database (the target)
and tableexpression is from the local db currentDB()

I need the syntax whereby the 'IN' is CurrentDB and the "tableexpression" is a remote access db.

That is to say, Inserting FROM a Remote.db into the CurrentDB().

Thanks,
final-prime
 
Do you mean
as an example:

dim dbr as Database
Set dbR = DBEngine(0).OpenDatabase(pathfile)

INSERT INTO ThisTable
SELECT ThatTable IN dbR

 
When you say IN (C:\docs\ThatDB.mdb) I don't

understand how Access would 'know' the connection has been Set to dbR.

What you have here is a only a path & a file name.
 
I said
IN 'C:\docs\ThatDB.mdb'

And that is the syntax. Paste the example into the query design window and alter it to suit your set-up and you will see. Why shouldn't Access be able to open a file from its exact address?

 
I get error message "Syntax Error in FROM Clause"

Function ri()
On Error GoTo x

Dim pathfile As String
Dim rxy As New Recordset
rxy.Open "tblpathFiles", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
pathfile = rxy!pathfiles
rxy.Close
Dim sql As String
Dim db As Database
Set db = CurrentDb()
sql = "INSERT INTO tblSubjectComps1 (StreetName ) SELECT StreetName FROM tblSubjectComps IN (" & pathfile & ")"
Debug.Print sql
db.Execute sql
db.Close
Exit Function
x:
MsgBox err.Description
End Function
''''''''''''''''''
INSERT INTO tblSubjectComps1 (StreetName ) SELECT StreetName FROM tblSubjectComps IN ("K:\Spatialest_Library\libArea11.mdb")
 
That is probably because you are missing the quotes:

Code:
sql = "INSERT INTO tblSubjectComps1 (StreetName ) SELECT StreetName FROM tblSubjectComps  IN ('"  & pathfile & "')"

You should end up with
IN 'C:\docs\ThatDB.mdb'

Note the single quotes.


 
INSERT INTO tblSubjectComps1 (StreetName ) SELECT StreetName FROM tblSubjectComps IN 'K:\Spatialest_Library\libArea11.mdb'

tested this sql. It gave no run-time error but also does not do the insert. As you see, the single quotes were used.
 
There could be several reasons why the query would fail, for example, there may be problems with unique keys. If you ran the query in code and did not use dbFailOnError, the query will fail silently. Probably the easiest way to find the problem is to paste the SQL into the query design window in SQL view and run from there. I might mention that a similar query works for me.

 
Upon debuging as you directed:

In the query you'll notice I am inserting only Streetname... Since both the input-output have primary indexes.....the Insert needs
BOTH the Street and primary key..................INSERT INTO tblsubjectcomps (UID,StreetName....

Thanks!

final prime
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top