whitespace
Registered User.
- Local time
- Today, 05:21
- Joined
- Aug 30, 2005
- Messages
- 51
Hello all,
Could anyone tell me the fastest way to pull Access query data into Excel using vba. Note we need to be able to amend the queries in a loop to automate report generation (so the criteria changes on each loop). We currently use something along the lines of that below but some queries to the server run so slow. Is this the quickest way to do it??
Many thanks for any help.
Could anyone tell me the fastest way to pull Access query data into Excel using vba. Note we need to be able to amend the queries in a loop to automate report generation (so the criteria changes on each loop). We currently use something along the lines of that below but some queries to the server run so slow. Is this the quickest way to do it??
Many thanks for any help.
Code:
s = "SELECT `KEY STAGE 3 RESULTS`.SchoolNo, `KEY STAGE 3 RESULTS`.Year, `KEY STAGE 3 RESULTS`.Sex, `KEY STAGE 3 RESULTS`.`KS3-En-Pupils`, `KEY STAGE 3 RESULTS`.`KS3-En-%L5`, `KEY STAGE 3 RESULTS`.`KS3-En-%L6`, `KEY STAGE 3 RESULTS`.`KS3-En-Pts`, `KEY STAGE 3 RESULTS`.`KS3-Ma-Pupils`, `KEY STAGE 3 RESULTS`.`KS3-Ma-%L5`, `KEY STAGE 3 RESULTS`.`KS3-Ma-%L6`, `KEY STAGE 3 RESULTS`.`KS3-Ma-Pts`, `KEY STAGE 3 RESULTS`.`KS3-Sc-Pupils`, `KEY STAGE 3 RESULTS`.`KS3-Sc-%L5`, `KEY STAGE 3 RESULTS`.`KS3-Sc-%L6`, `KEY STAGE 3 RESULTS`.`KS3-Sc-Pts`, `KEY STAGE 3 RESULTS`.`KS3-IT-Pupils`, `KEY STAGE 3 RESULTS`.`KS3-IT-%L5`, `KEY STAGE 3 RESULTS`.`KS3-IT-%L6`, `KEY STAGE 3 RESULTS`.`KS3-IT-Pts`, `KEY STAGE 3 RESULTS`.`KS3-Pub-Number`, `KEY STAGE 3 RESULTS`.`KS3-Pub-En-%L5`, `KEY STAGE 3 RESULTS`.`KS3-Pub-Ma-%L5`, `KEY STAGE 3 RESULTS`.`KS3-Pub-Sc-%L5`, `KEY STAGE 3 RESULTS`.`KS3-Pub-APts-%L5` "
s = s & "FROM `H:\LSIP\Current Year\Special\Special`.`KEY STAGE 3 RESULTS` `KEY STAGE 3 RESULTS` "
s = s & "WHERE (`KEY STAGE 3 RESULTS`.SchoolNo=" & Chr(39) & scno & Chr(39) & ") AND (`KEY STAGE 3 RESULTS`.Year>='2001') AND (`KEY STAGE 3 RESULTS`.Sex='M') "
Sheets("GetKS3Male").Select
Range("A1").Select
With Selection.QueryTable
.Connection = Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=H:\LSIP\Current Year\Special\Special.mdb;DefaultDir=H:\LSIP\Current Year\Special;DriverId=25;FIL=MS " _
), Array("Access;MaxBufferSize=2048;PageTimeout=5;"))
.CommandText = s
.Refresh BackgroundQuery:=False
End With