Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Exporting contents of range to Access...HELP!

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?

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")) & ";" 'Range("C22:E22") & ";"
'('skelly','2','2');"

'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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data range from Excel to Access Shep Excel Programming 3 February 5th 07 05:10 PM
Exporting datagrid contents to Excel using ASP.NET Mike Excel Programming 0 March 14th 06 07:40 PM
Exporting excel cell contents to word document kaiser Excel Programming 2 September 12th 05 11:24 AM
Exporting multiple cell contents into word document Davy L Excel Worksheet Functions 1 September 6th 05 04:06 AM
Exporting from Access tamxwell Excel Worksheet Functions 3 June 29th 05 03:04 PM


All times are GMT +1. The time now is 03:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"