createquerydef with all but last column

supmktg

Registered User.
Local time
Yesterday, 19:36
Joined
Mar 25, 2002
Messages
360
I am exporting a table to a csv file using the following code:

Code:
strSQL = "Select * from Table1 Where GrpNo = 2"
Set qdf = CurrentDb.CreateQueryDef("qryGrp2", strSQL)
qdf.Close
DoCmd.TransferText acExportDelim, , qdf.name, "C:\Grp2.csv", True

The columns in the table may change, but the last column should always be 'Grpno'. I would like to prevent the 'GrpNo' column from being exported.

Can someone point me in the direction of how to do that?

Thanks,
Sup
 
Thanks Trevor.

If it helps anyone, I built the Select statement using all of the fields except 'GrpNo' using the following code:

Code:
Dim rstFlds As DAO.Recordset
Dim fld As DAO.Field
Dim strSQL As String

Set rstFlds = CurrentDb.TableDefs("Table1").OpenRecordset

    strSQL = "Select "

    For Each fld In rstFlds.Fields
        If fld.name <> "GrpNo" Then
            strSQL = strSQL & fld.name & ", "
        End If
    Next fld
    
    strSQL = Left(strSQL, (Len(strSQL) - 2))
    
    strSQL = strSQL & " FROM Table1 WHERE GrpNo = 2"

rstFlds.Close
Set rstFlds = Nothing

Sup
 
Sup pleased to read you have a working solution.

Hope you have a good weekend.:)
 

Users who are viewing this thread

Back
Top Bottom