Can anyone help me here ?
I want to get the sql server table into access database .
I have tried below code from some Internet source but it didn't worked
Dim conn As ADODB.Connection '<<<connection to SQL Server
Dim rst As ADODB.Recordset '<<<Recordset for SQL Server
Dim dbConn As ADODB.Connection '<<<connection for current access db
Dim sqlq As String
'create connection to external database
Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & ServerName & ""
'On Error GoTo err
'Db.Open "Provider=SQLOLEDB.1;Data Source=" & ServerName & ";" & _
'Initial Catalog=" & DatabaseName & ";User ID=TestID;Password=srm"
'pull records from database into recordset
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM Tbl_HRBPO_BAC_OMT_CS_Data "
Set dbConn = CurrentProject.Connection
'move through each record and load it into the local access database using Execute method
rst.MoveFirst
Do While Not rst.EOF
sqlq = "INSERT INTO newt VALUES('" & rst.Fields(0).Value & "', '" & rst.Fields(1).Value & "')"
dbConn.Execute sqlq
rst.MoveNext
Loop
dbConn.Close
Set dbConn = Nothing
rst.Close
conn.Close
Set rst = Nothing
Set conn = Nothing
End Sub
Thanks in advance