Douglas J. Steele said:
That's fine. You need 1 query, and one bit of code.
Assuming you want the files to include the city name as part of the file
name, you'd do something like the following untested air code:
Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef
Dim rsCurr As DAO.Recordset
Dim strCity As String
Dim strFile As String
Dim strSQL As String
Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset("SELECT CityNm FROM Cities")
Do Until rsCurr.EOF = False
strCity = rsCurr!CityNm
strFile = "C:\Output Files\" & strCity & ".txt"
strSQL = "SELECT Field1, Field2, Field3 " & _
"FROM MyTable " & _
"WHERE City = '" & strCity & "'"
Set qdfCurr = dbCurr.QueryDefs("MyCityQuery")
qdfCurr.SQL = strSQL
DoCmd.TransferText acExportDelim, , "MyCItyQuery", strFile
rsCurr.MoveNext
Loop
rsCurr.Close
Set rsCurr = Nothing
Set qdfCurr = Nothing
Set dbCurr = Nothing