Hi,
I have the following code to export a query result to Excel.
At present, this creates a file with all records and the path shows the country for country code 1.
I have never created a loop but understand that this would enable me to create a separate file for each country which is what I need.
Is someone able to show me how to create the loop. I have tried various solutions from Google but without success!
Further, once the loop runs and separate files are created, is it possible to update the Country variable each time the loop changes to a new record?
Would appreciate any assistance with this.
Thanks
I have the following code to export a query result to Excel.
Code:
Dim db As DAO.Database
Dim rs As Recordset
Set db = CurrentDb
Dim mySql As String
Dim MYPath As String
Dim Country As String
mySql = "SELECT * From QryMissingData"
Country = DLookup("Country", "tblCountries", "CountryCode = 1")
MYPath = "Missing Data For " & Country & " Created " & Date
db.CreateQueryDef "CountryFile", mySql
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "CountryFile", "C:\KPMG\Missing data Files\" & MYPath & "", True
DoCmd.DeleteObject acQuery, "CountryFile"
At present, this creates a file with all records and the path shows the country for country code 1.
I have never created a loop but understand that this would enable me to create a separate file for each country which is what I need.
Is someone able to show me how to create the loop. I have tried various solutions from Google but without success!
Further, once the loop runs and separate files are created, is it possible to update the Country variable each time the loop changes to a new record?
Would appreciate any assistance with this.
Thanks