Depends on how your data is stored. In your query, you can use basically the same thing, something like:
Select blah blah blah from MyTable WHERE
Month([MyDateField]) = Month(DateSerial(Year(Now),Month(Now),0)) AND
Year([MyDateField]) = Year(DateSerial(Year(Now),Month(Now),0))
...
The TransferText method has an argument called
filename that can be used to name the file you are exporting to. Look up TransferText in VB help for more info.
You could also make a function like this (in a regular module) and then use it both in your query and in your TransferText call.
Code:
Public Function LastMonth() as Date
LastMonth = DateSerial(Year(Now),Month(Now),0)
End Function
You would use it like this:
Select blah blah blah from MyTable WHERE
Month([MyDateField]) = Month(LastMonth) AND
Year([MyDateField]) = Year(LastMonth)
...
in your query, and something like this in your TransferText call:
Code:
Docmd.TransferText acExportDelim, , "MyQuery", _
Format(Month(LastMonth),"mmmm") & ".txt", True
(the important parts being "MyQuery", and the
Format(Month(LastMonth),"mmmm") & ".txt" parts.
HTH,
Russell