Hello, I'm new here and would like to ask a VBA question.

Below is some VBA code for MS-Access.
It is intended to do two things.

1) create multiple .txt files using the variable value of field "RUStmtPeriod" as the file name.
2) determine the contents of each .txt file by using the current value of field "RUStmtPeriod" as the criterion. (This is the part I cannot get to work).

Can you please help?

Function ExportFiles()

Dim dbsCurrent As DATABASE
Dim rstFilter As Recordset
Dim rstBaseTable As Recordset
Dim Suffix As String
Dim Filename As String
Dim strQryFilter As String

Set dbsCurrent = CurrentDb()
Set rstFilter = dbsCurrent.OpenRecordset("qExportFilter", dbOpenDynaset)
Set rstBaseTable = dbsCurrent.OpenRecordset("qUpload", dbOpenDynaset)

With rstFilter
Do Until .EOF

strFilterRollup = "[RUStmtPeriod] = '" & ![RUStmtPeriod] & "'"
strQryFilter = BuildCriteria("RUStmtPeriod", dbText, strFilterRollup)

Suffix = ![RUStmtPeriod]
Filename = "c:\data\" & Suffix & ".txt"

DoCmd.TransferText acExportDelim, "qUpload Export Specification", "qUpload", Filename, hasfieldnames:=True


End With


End Function