W
WhytheQ
I've got the following code. What I'm trying to is export the contents
of a range into an Access table called Scorers. The range C22:E22
contains 'fred','2','2' which correspond to the fields name/age/score.
An error occurs when creating the SQL string.
Do I need to use a loop and individually move each bit of data? Or
should I be using a completely different tact.
Any help greatly appreciated
Jason
Sub AddToAccess()
Dim cnAccess As ADODB.Connection
Dim sConnect As String
Dim sSQL As String
'create connection string
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.Path & "\Access
Experiment.mdb"
'create SQL string
sSQL = "INSERT INTO Scorers (name,age,score) VALUES (" & _
Application.Transpose(Range("C22:E22")) & ";"
'make connection and get get the SQL query recordset
Set cnAccess = New ADODB.Connection
cnAccess.ConnectionString = sConnect
cnAccess.Open
cnAccess.Execute sSQL, , adCmdText + adExecuteNoRecords
'close the connection
cnAccess.Close
Set cnAccess = Nothing
End Sub
of a range into an Access table called Scorers. The range C22:E22
contains 'fred','2','2' which correspond to the fields name/age/score.
An error occurs when creating the SQL string.
Do I need to use a loop and individually move each bit of data? Or
should I be using a completely different tact.
Any help greatly appreciated
Jason
Sub AddToAccess()
Dim cnAccess As ADODB.Connection
Dim sConnect As String
Dim sSQL As String
'create connection string
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.Path & "\Access
Experiment.mdb"
'create SQL string
sSQL = "INSERT INTO Scorers (name,age,score) VALUES (" & _
Application.Transpose(Range("C22:E22")) & ";"
'make connection and get get the SQL query recordset
Set cnAccess = New ADODB.Connection
cnAccess.ConnectionString = sConnect
cnAccess.Open
cnAccess.Execute sSQL, , adCmdText + adExecuteNoRecords
'close the connection
cnAccess.Close
Set cnAccess = Nothing
End Sub