I am trying to open two databases and read from a table in one and insert it's data into a table in the other.
The database I am inserting into is in the current database (CurrentDB) and the databaase I am reading from (RemoteDB) is in another directory.
If I have the table in RemoteDB linked in CurrentDB, so that RemoteDB table is resident in CurrentDB, the following code works just fine:
Dim [COLOR=green yellow]CDB As New ADODB.Connection
Dim CRS As New ADODB.Recordset
Dim DataTo As String
Dim DataFrom As String
DataTo = "Inset_Field_X, Inset_Field_Y"
DataFrom = "FieldNameX = 'X' AND FieldNameY = 'Y'"
[COLOR=green yellow]CDB[/color].Open "CurrentDB"
CRS.Open _
"INSERT INTO tbl_Input_In_CBD (" & DataTo & ") SELECT * FROM tbl_Output_From_DB _
WHERE " & DataFrom & " ", _
[COLOR=green yellow]CDB[/color], adOpenDynamic, adLockOptimistic
[/color]
But, if I don't link the table in CurrentDB but try to open RemoteDB directly, I cannot make it work.
I need help on the INSERT syntax (I haven't changed the INSERT in the example below. All I have done is added the two bolded lines).
Here is what I have done so far (it blows-up at the CRS.Open “INSERT....... Statement):
Dim [COLOR=green yellow]CDB As New ADODB.Connection
Dim CRS As New ADODB.Recordset
Dim [COLOR=green yellow]RDB[/color] As New ADODB.Connection
Dim DataTo As String
Dim DataFrom As String
DataTo = "Inset_Field_X, Inset_Field_Y"
DataFrom = "FieldNameX = 'X' AND FieldNameY = 'Y'"
[COLOR=green yellow]CDB[/color].Open "CurrentDB"
[COLOR=green yellow]RDB[/color].Open "RemoteDB"
CRS.Open _
"INSERT INTO tbl_Input_In_CBD (" & DataTo & ") SELECT * FROM tbl_Output_From_DB _
WHERE " & DataFrom & " ", _
[COLOR=green yellow]CDB[/color], adOpenDynamic, adLockOptimistic
[/color]
Any help would be appreciated!
Thanks.
The database I am inserting into is in the current database (CurrentDB) and the databaase I am reading from (RemoteDB) is in another directory.
If I have the table in RemoteDB linked in CurrentDB, so that RemoteDB table is resident in CurrentDB, the following code works just fine:
Dim [COLOR=green yellow]CDB As New ADODB.Connection
Dim CRS As New ADODB.Recordset
Dim DataTo As String
Dim DataFrom As String
DataTo = "Inset_Field_X, Inset_Field_Y"
DataFrom = "FieldNameX = 'X' AND FieldNameY = 'Y'"
[COLOR=green yellow]CDB[/color].Open "CurrentDB"
CRS.Open _
"INSERT INTO tbl_Input_In_CBD (" & DataTo & ") SELECT * FROM tbl_Output_From_DB _
WHERE " & DataFrom & " ", _
[COLOR=green yellow]CDB[/color], adOpenDynamic, adLockOptimistic
[/color]
But, if I don't link the table in CurrentDB but try to open RemoteDB directly, I cannot make it work.
I need help on the INSERT syntax (I haven't changed the INSERT in the example below. All I have done is added the two bolded lines).
Here is what I have done so far (it blows-up at the CRS.Open “INSERT....... Statement):
Dim [COLOR=green yellow]CDB As New ADODB.Connection
Dim CRS As New ADODB.Recordset
Dim [COLOR=green yellow]RDB[/color] As New ADODB.Connection
Dim DataTo As String
Dim DataFrom As String
DataTo = "Inset_Field_X, Inset_Field_Y"
DataFrom = "FieldNameX = 'X' AND FieldNameY = 'Y'"
[COLOR=green yellow]CDB[/color].Open "CurrentDB"
[COLOR=green yellow]RDB[/color].Open "RemoteDB"
CRS.Open _
"INSERT INTO tbl_Input_In_CBD (" & DataTo & ") SELECT * FROM tbl_Output_From_DB _
WHERE " & DataFrom & " ", _
[COLOR=green yellow]CDB[/color], adOpenDynamic, adLockOptimistic
[/color]
Any help would be appreciated!
Thanks.