Importing access data into excel spreadsheet

Phoenix_Turn

New Member
Joined
May 11, 2011
Messages
37
Hi all,

In access at the moment, I have 3/4 columns. First one: customer name, 2nd: their address, 3rd: phone number.

Now i have this code here at the moment to insert in the excel spreadsheet however it's not fully working. Heres the code:

Dim cnnNames As ADODB.Connection, rstName As ADODB.Recordset 'Dim strNameDatabase As String, strConnectionString As String
Dim rngValue As Range
strNameDatabase = ActiveWorkbook.Path & "\Clients.accdb"'strConnectionString = "Provider=Microsoft.Ace.OLEDB.<wbr>12.0;Data Source=" & strNameDatabase & _
";Persist Security Info=False"

'Set rstName = New ADODB.Recordset
'rstName.Open "Select [Customer] from ClientsTable", strConnectionString, adOpenStatic



Application.ActiveWorkbook.<wbr>Worksheets("Cl").Activate
Application.ActiveWorkbook.<wbr>Worksheets("Cl").Range("<wbr>A1").Select

rngValue = Application.ActiveWorkbook.<wbr>Worksheets("Cl")

Do While Not rstName.EOF

ActiveCell.Offset(1, 0).Value = rstName("Cust")


rstName.MoveNext

Loop

Any idea why its wrong? I want to move it using ADO
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You're not moving the selection as you go. Also, this is getting only one field, the "Cust" field. Is that all you want?

Code:
Dim cnnNames As ADODB.Connection, rstName As ADODB.Recordset 'Dim strNameDatabase As String, strConnectionString As String
Dim rngValue As Range
 
strNameDatabase = ActiveWorkbook.Path & "\Clients.accdb" 'strConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & strNameDatabase & _
";Persist Security Info=False"
'Set rstName = New ADODB.Recordset
'rstName.Open "Select [Customer] from ClientsTable", strConnectionString, adOpenStatic
 
[COLOR=red]Worksheets("Cl").Activate     [/COLOR][COLOR=green]' ActiveWorkbook is assumed[/COLOR]
[COLOR=red]Set rngValue = Range("A1")   [COLOR=green]' ActiveSheet is assumed[/COLOR][/COLOR]
[COLOR=red]rngValue.Select[/COLOR]
 
Do While Not rstName.EOF
[COLOR=red]Set rngValue = rngValue.Offset(1, 0)[/COLOR]
[COLOR=red]rngValue.Value = rstName("Cust")[/COLOR]
 
rstName.MoveNext
Loop
 
Upvote 0

Forum statistics

Threads
1,224,508
Messages
6,179,189
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top