Apply filter in treansfertext method

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

Dear helper,

I used “Docmd.transfertext” to export a query result to a
text file. My code is as follows:

DoCmd.TransferText acExportDelim, , "customer -
testing", "i:\accnting\HI mailing database\testing1.txt", -
1

My question is how to add a filter in the query via code.
I have a form to display 5 filter fields, which the user
can select from. The user can use one field or any
combination. I tried to hardcore all the filters in the
query. It only works when the user enters all 5 fields.
If the user has any empty field, the query result will be
empty. I have no problem to capture the selected filters
as a string but I do not know how to apply the string
into the above code “Docmd.transfertext………”

Please help. I am very appreciated

Thank you.
 
You could rewrite the query before calling the TransferText call. Most of the query should
be the same, just the WHERE part changing.

strSelect = "SELECT .... FROM ..."
strOrderBy = " ORDER BY ....;"
strWhere = " WHERE ...." 'you would concatenate together this part with your filters.

Next, rewrite the stored query.

CurrentDb.QueryDefs("customer - testing").SQL = strSelect & strWhere & strOrderBy

Now, run your TransferText
 
Back
Top