Connecting Tech Pros Worldwide Forums | Help | Site Map

Exporting from Access to specific cell in Excel

Member
 
Join Date: Oct 2006
Posts: 34
#1: Jul 10 '07
Hi,

I have a template in Excel, that I want to populate. The problem is that I need to export a table/report in Access into these specific cells in an Excel sheet that already exists.

How can that be done?

Regards,
Riun

Newbie
 
Join Date: Nov 2006
Posts: 10
#2: Jul 10 '07

re: Exporting from Access to specific cell in Excel


Hi, I use this code below and have had no issues with it.

Basically I create a query in Access and copy and paste into the SQL area of this macro.

Option Explicit

Dim cnnDW As ADODB.Connection
Dim rsDW As ADODB.Recordset
Dim sQRY As String
Dim strDWFilePath As String

Sub GetData()

On Error GoTo Err:
strDWFilePath = "Location of the Database.mdb"

Set cnnDW = New ADODB.Connection

'Import all Data I want into Sheet4

Set rsDW = New ADODB.Recordset
'ASV N Week by Contract
Sheet4.Range("B5:BB23").ClearContents
cnnDW.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDWFilePath & ";"
sQRY = "SELECT * FROM tblTableName " & _
"WHERE tblTableName.Name = 'Jez' "
rsDW.CursorLocation = adUseClient
rsDW.Open sQRY, cnnDW, adOpenStatic, adLockReadOnly
Application.ScreenUpdating = False
Sheet4.Range("B5").CopyFromRecordset rsDW
rsDW.Close
Set rsDW = Nothing
cnnDW.Close
Set cnnDW = Nothing
Exit Sub
Err:
MsgBox VBA.Err
End

You will need to change Sheet4 & the Range to what ever you need it to be and replace the SQL Statement too.

Jez
Member
 
Join Date: Oct 2006
Posts: 34
#3: Jul 10 '07

re: Exporting from Access to specific cell in Excel


Thank you very much,Jez. I will certainly try it out.
Reply


Similar Microsoft Access / VBA bytes