PDA

View Full Version : INSERT INTO action query question



beginner
09-24-2005, 03:54 PM
hello......

i would like to append a Table records to a remote Table, i only got some coding ref. from some source as below but didn't work, appreciate any adv. Tks.

Dim sql As String

sql = "INSERT INTO " & [remote_Table] (field1, field2) IN & _
" C:\BackUp.mdb SELECT " & [local_Table].field1 & ", " & _
[local_Table].field2 & " FROM [local_Table]"

DoCmd.OpenQuery "sql"

geekgirlau
09-26-2005, 10:18 PM
Have a link to the remote table
Create your append query normally and test it
Do you need some criteria there? Your SQL would append all records to the remote table
Once you are happy with the query, select View | SQL View to see the SQL statement
Copy the SQL statement and paste it into your code
You can't use "OpenQuery" in your code as the query has not been saved - use "RunSQL" instead

Dim strSQL As String


strSQL = "INSERT INTO tbl_Employee ( txt_Emp_FirstName, txt_Emp_Surname ) " & _
"SELECT txt_Cust_FirstName, txt_Cust_Surname " & _
"FROM tbl_Customer " & _
"WHERE lng_Cust_ID = 1"

DoCmd.RunSQL strSQL

Norie
09-27-2005, 07:45 AM
beginner

Does it work if you remove the quotes?

DoCmd.OpenQuery sql

beginner
09-27-2005, 10:25 PM
hi geekgirlau and Norie.....tks for the adv.

but i need sometime to figure it out first.....thanks again and will be back.

BR/