Hi, Jonas.
is there any way to only selectively export rows of a table using the
transfertext command and a parameter to dynamically select some rows of the
table?
The TransferText( ) method doesn't have a parameter for "selective records."
However, there's no reason one cannot use a query for identifying these
selective records and then using the TransferText( ) method to export that
query.
In the following example, a temporary query named qryTemp must be created
first. (It can have any valid SQL statement. It will be overwritten by the
procedure, so don't worry what's in the original SQL statement of this
query.) A public procedure is created to call the TransferText( ) method:
Public Sub TransferTextWParam(sDataSrc As String, sFldName As String,
sCriteria As String)
On Error GoTo ErrHandler
Dim qry As QueryDef
Dim sqlStmt As String
sqlStmt = "SELECT * " & _
"FROM " & sDataSrc & _
" WHERE (" & sFldName & " = '" & sCriteria & "');"
Set qry = CurrentDb().QueryDefs("qryTemp")
qry.sql = sqlStmt
DoCmd.TransferText acExportDelim, "SpecName", qry.Name,
"C:\Work\XferText.txt", True
CleanUp:
Set qry = Nothing
Exit Sub
ErrHandler:
MsgBox "Error in TransferTextWParam( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp
End Sub
.... where "SpecName" is the name of the export specification and
"C:\Work\XferText.txt" is the path and file name of the exported file. This
example uses a string parameter, so if your parameter is either numeric or a
date, change the SQL syntax and the parameter passed to the procedure
appropriately.
This procedure can be called from another procedure as in the following
example:
Public Sub testXferTextWParam()
On Error GoTo ErrHandler
Dim sTable As String
Dim sField As String
Dim sParam As String
sTable = "tblMyTable"
sField = "SomeField"
sParam = "SomeValue"
Call TransferTextWParam(sTable, sField, sParam)
Exit Sub
ErrHandler:
MsgBox "Error in testXferTextWParam( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
End Sub
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.