View Full Version : target database as variable


alswah
11-05-2004, 09:18 PM
hi

thes is my Querie in vbcode.

DoCmd.RunSQL "INSERT INTO table1 ( user_num,user_name ) IN 'db2' SELECT [teble].user_num, [teble].user_name FROM teble; ", -1
the probleme is

i need to change target database (db2) to variable.

thes is my tray:

Dim Path As String
Path = Me!dbpath
DoCmd.RunSQL "INSERT INTO table1 ( user_num,user_name ) IN 'Path' SELECT [teble].user_num, [teble].user_name FROM teble; ", -1

it's err :confused:

can you help me PLZ ?

Jon K
11-06-2004, 05:13 PM
You don't need a variable at all. Just leave the path outside of the quoted string and concatenate it with &, that is

DoCmd.RunSQL "INSERT INTO table1 ( user_num,user_name ) IN '" & Me.dbpath & "' SELECT [teble].user_num, [teble].user_name FROM teble; ", -1


Note
The file extension must also be included in the path e.g.
C:\My Documents\db2.mdb
.