Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access VBA using Transfertext to create files with criteria

Status
Not open for further replies.

ryandougherty

Technical User
Aug 10, 2007
1
US
I am creating multiple txt files from a query, and I need the VBA script to input criteria from a list into the query each time it is saved.

My issue is that the docmd.transfertext method does not SEEM to allow me to do this.

Any suggestions?

Here is the code thus far: (ignore REM'd out lines)

==============================
Public Sub cmdPublish_Click()


Dim dbs As Database, rstList
Dim LIST As String
Dim SECTION As String

'1ST SECTION

Set dbs = CurrentDb
Set rstList = dbs.OpenRecordset("q_eventlawson_cd_list")
rstList.MoveLast
rstList.MoveFirst
Do Until rstList.EOF
Let LIST = rstList!EventLawson_cd
DoCmd.TransferText acExportDelim, "Q_export_by_eventname Export Specification", "q_export_by_eventname", Forms![form_Rpt_Publishing]![txtPath] & LIST & "_Email_FY06-FY07.csv", True
'DoCmd.Close

rstList.MoveNext
Loop

End Sub

==============================

 
ryan

I think that you need to change parameter value of your saved query for every record you get from your rstList.
Something
Code:
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDefs
Dim rstList As DAO.Recordset
Dim SECTION As String

    '1ST SECTION
    
Set dbs = CurrentDb
Set rstList = dbs.OpenRecordset("q_eventlawson_cd_list")
Set qdf = dbs.QueryDefs("q_export_by_eventname")
With rstList
   .MoveLast
   .MoveFirst
   Do Until .EOF
      qdf.Parameters("YourParameterNameHere")= .Fields("EventLawson_cd")
      DoCmd.TransferText acExportDelim, "Q_export_by_eventname Export Specification", "q_export_by_eventname", Forms![form_Rpt_Publishing]![txtPath] & .Fields("EventLawson_cd") & "_Email_FY06-FY07.csv", True
      .MoveNext
   Loop
   .Close
End With
Set rst = Nothing
Set qdf = Nothing
Set dbs = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top