Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Importing / Linking / May 2005

Tip: Looking for answers? Try searching our database.

Export to file from Access2K

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
A E - 30 May 2005 23:15 GMT
Hi,

I'm trying to run a For each statement, I end up in the debugger with
Run-time error '3251' Operation is not supported for this type of object.
What I'm trying to do is to put the Fieldnames in top of the exported file.

This is as far as I've reached:

Dim rsCurr As DAO.Recordset
Dim fldCurr As DAO.Field
Dim intFile As Integer
Dim curTotal As Currency
Dim strFile As String
Dim strOutput As String
Dim varData As Variant

  strFile = "C:\Output.txt"
  intFile = FreeFile()
  sngTotal = 0#

  Set dbCurr = CurrentDb()
  Set rsCurr = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot,
dbForwardOnly)

 If rsCurr.EOF = False Then
     Open strFile For Output As #intFile
     varData = ""
'"This is the part that doesn't work"
     For Each fldCurr In rsCurr
        varData = varData & fldCurr.Name & ","
     Next fldCurr

Best regards, AE
Douglas J. Steele - 31 May 2005 00:25 GMT
For Each fldCurr In rsCurr.Fields

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hi,
>
[quoted text clipped - 30 lines]
>
> Best regards, AE
Joe Fallon - 01 Jun 2005 00:40 GMT
Here is a sample of some general export code:

Public Sub ExportDelim(strTable As String, strExportFile As String,
strDelimiter As String, Optional blnHeader As Boolean)

  'strTable is the table or query name
  'strExportFile is the full path and name of file to export to
  'strDelimiter is the field deliminator to use like Chr(9) for tab or
Chr(44) for comma or ??

  Dim fld As Field
  Dim varData As Variant
  Dim rs As Recordset
  Dim intFileNum As Integer

  'set recordset on table or query
  Set rs = CurrentDb.OpenRecordset(strTable, dbOpenSnapshot)

  'get file handle and open for output
  intFileNum = FreeFile()
  Open strExportFile For Output As #intFileNum

  If blnHeader Then
     'output the header row if requested
     varData = ""
     For Each fld In rs.Fields   'traverse the fields collection
        varData = varData & fld.Name & strDelimiter
     Next

     'remove extra last strDelimiter
     varData = Left(varData, Len(varData) - 1)

     'write out the header row
     Print #intFileNum, varData
  End If

  'now your data
  Do While Not rs.EOF
     varData = ""
     'concatenate the data row
     For Each fld In rs.Fields
        varData = varData & fld.Value & strDelimiter
     Next

     'remove extra last strDelimiter
     varData = Left(varData, Len(varData) - 1)

     'write out data row
     Print #intFileNum, varData

     rs.MoveNext
  Loop

  Close #intFileNum
  rs.Close
  Set rs = Nothing
End Sub

Signature

Joe Fallon
Access MVP

> Hi,
>
[quoted text clipped - 30 lines]
>
> Best regards, AE
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.