LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Bring Queries from Access into Excel

Hi, This is my vb code to bring data from access to excel. How is it possible
to duplicate this and bring in more than 1 sql and paste elsewhere on the
sheet? this below works for the one sql written, how can I write another sql
and paste on another cell in the sheet?

Sub GetASVNDistrict()

On Error GoTo Err:
strDWFilePath = "H:\NCHO\Housing Services\Data Warehouse\HSG Data
Warehouse.mdb"

Set cnnDW = New ADODB.Connection
Set rsDW = New ADODB.Recordset

Sheet4.Range("B5:BB22").ClearContents

cnnDW.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDWFilePath & ";"

sQRY = "TRANSFORM Count([qryNoAccess(byAppt)].WRNumber) AS
CountOfWRNumber " & _
"SELECT [qryNoAccess(byAppt)].CouncilName " & _
"FROM [qryNoAccess(byAppt)] " & _
"WHERE ((([qryNoAccess(byAppt)].BANumber) < 'HSG0008 20') And
(([qryNoAccess(byAppt)].AppointmentOutcomeID) = 'N') And
(([qryNoAccess(byAppt)].ActionTypeID) = 'AS')) " & _
"GROUP BY [qryNoAccess(byAppt)].CouncilName " & _
"PIVOT [qryNoAccess(byAppt)].Week"

rsDW.CursorLocation = adUseClient
rsDW.Open sQRY, cnnDW, adOpenStatic, adLockReadOnly

Application.ScreenUpdating = False
Sheet4.Range("B5").CopyFromRecordset rsDW

rsDW.Close
cnnDW.Close

Set rsDW = Nothing
Set cnnDW = Nothing

Exit Sub

Err:
MsgBox "The following error has occured-" & vbCrLf & vbCrLf & VBA.Error,
vbCritical, "HSG NA Trending"
MsgBox VBA.Err

End Sub

thanks :-)

Jez

 
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
Access Queries not seen in Excel RGBrighton Excel Discussion (Misc queries) 0 February 23rd 10 06:51 PM
Access Queries into Excel TKM Excel Worksheet Functions 1 November 13th 06 08:54 PM
Queries from Excel 2003 to Access Osmar Mateus Excel Discussion (Misc queries) 4 April 12th 06 04:15 PM
Running SQL queries for Access using Excel VBA ibeetb Excel Programming 2 August 31st 05 07:56 AM
Excel Driven Access Queries Ed Excel Programming 2 January 14th 04 09:56 PM


All times are GMT +1. The time now is 05:49 PM.

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"