Hello,
I have a fairly urgenet need to work out how to connect to an extrenal access database and take all records from a named table and paste them into a table of identical structure in my local database.
I have tried transfering the table, but ran into problems with the imported table being renamed with copies buiding up suffixed with 1,2 3 etc.
I would like to import all the records and put them into my local table. This is what I have so far and it doent work. As a test Im setting the external table name which provides the data to 1250
I would reall appreciate help with this - thanks Mark
I have a fairly urgenet need to work out how to connect to an extrenal access database and take all records from a named table and paste them into a table of identical structure in my local database.
I have tried transfering the table, but ran into problems with the imported table being renamed with copies buiding up suffixed with 1,2 3 etc.
I would like to import all the records and put them into my local table. This is what I have so far and it doent work. As a test Im setting the external table name which provides the data to 1250
Code:
Public Sub GemAcTablePopulate()
Dim cnn As New ADODB.Connection
Dim myrecordset As ADODB.Recordset
Dim CnnStr As String
Dim strSQL As String
CnnStr = "Provider=Microsoft.Jet.OLEDB.4.0;"
'CnnStr = CnnStr + "User ID=Admin;"
CnnStr = CnnStr + "Data Source=M:\gem\Gem.mdb"
Set cnn = New ADODB.Connection
cnn.ConnectionString = CnnStr
cnn.CursorLocation = adUseNone
cnn.Open
Set myrecordset = New ADODB.Recordset
With myrecordset
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockReadOnly
Dim GemAccount As Variant
GemAccount = 1250
strSQL = "SELECT * FROM " & GemAccount
.Open strSQL, cnn
If .RecordCount > 0 Then
myrecordset.Sort = "date desc"
strSQL = "INSERT INTO local_GemAcTable (date, type) VALUES (date, type);"
End If
.Close
End With
Set myrecordset = Nothing
cnn.Close
Set cnn = Nothing
End Sub
I would reall appreciate help with this - thanks Mark