Hi Amy,
I'm not sure it's possible to do this in a macro, but it can certainly
be done using VBA.
The general idea is
1) open a recordset containing just a list of agencyIDs that need to be
exported
2) for each agencyID, export the records for just that agency.
The VBA could look vaguely like this:
Dim dbD as DAO.Database
Dim rsAgencies As DAO.Recordset
Dim strFilespec As String
Dim lngAgencyID As Long
Dim strSheet As String
Dim strSQL As String
Const SQL1 = "SELECT * INTO [Excel 8.0;HDR=Yes;Database="
Const SQL2 = "FROM qryRecordsToExport WHERE AgencyID="
Set dbD = CurrentDB()
Set rsAgencies = dbD.OpenRecordset("qryAgenciesToExport", _
dbOpenSnapshot)
strFilespec = "C:\Folder\File.xls"
Do Until rsAgencies.EOF
'Get AgencyID
lngAgencyID = rsAgencies.Fields("AgencyID").Value
strSheet = CStr(lngAgencyID)
'Assemble the SQL query to export one agency
strSQL = SQL1 & strFilespec & ";].[" & strSheet _
& SQL2 & lngAgencyID & ";"
'export it
dbD.Execute strSQL, dbFailOnError
rsAgencies.MoveNext
Loop
rsAgencies.Close
Hi I need to export a query into excel , in the query i am ordering by the
agencyID field and i need to put each agency on its own page so when an
agencyID changes it should export the upcoming data to a new page in excel-
does anybody know if thats even possible- im using a macro to export the
query- or is there some way to do this in code?