Joe
Your code has been a big help. However, program execution stops at
Set rs = CurrentDb.OpenRecordset(strTable, dbOpenSnapshot)
I get Run-time error 91, “Object variable or With block variable not setâ€
My Set statement is identical to yours, except for a query name string litera
instead of strTable
I have Dim statements
Dim rs As Recordset
Dim CurrentDb as Database (I added this one, but it didn’t help
Any idea why I am getting this error
Thanks again
ctda
----- Joe Fallon wrote: ----
If you write VBA code you can do pretty much anything you like with the dat
as you write it to the file
You should build 2-3 procedures simialr to this (1 for each major section o
your file) and then call them when needed. If you take your time and revie
this code you will see it is not really that difficult to follow. Then tak
the ideas and expand on them. (e.g. need data from 2 tables - open
recordsets!
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 nam
'strExportFile is the full path and name of file to export t
'strDelimiter is the field deliminator to use like Chr(9) for tab o
Chr(44) for comma or ?
Dim fld As Fiel
Dim varData As Varian
Dim rs As Recordse
Dim intFileNum As Intege
'set recordset on table or quer
Set rs = CurrentDb.OpenRecordset(strTable, dbOpenSnapshot
'get file handle and open for outpu
intFileNum = FreeFile(
Open strExportFile For Output As #intFileNu
If blnHeader The
'output the header row if requeste
varData = "
For Each fld In rs.Fields 'traverse the fields collectio
varData = varData & fld.Name & strDelimite
Nex
'remove extra last strDelimite
varData = Left(varData, Len(varData) - 1
'write out the header ro
Print #intFileNum, varDat
End I
'now your dat
Do While Not rs.EO
varData = "
'concatenate the data ro
For Each fld In rs.Field
varData = varData & fld.Value & strDelimite
Nex
'remove extra last strDelimite
varData = Left(varData, Len(varData) - 1
'write out data ro
Print #intFileNum, varDat
rs.MoveNex
Loo
Close #intFileNu
rs.Clos
Set rs = Nothin
End Su
--
Joe Fallo
Access MV
ctdak said:
TransferText: 1) I have to add two unique header records and one uniqu
trailing record, 2) I have to combine fields that have been output fro
different tables, 3) I have to conditionally omit fields altogether i
certain records depending on the contents of other fields, and 4) I have t
change the output format of some field types (such as removing the time in
Date/Time field and the $ sign in a Currency field). These types of thing
can easily be done with Basic code, but can they be done from VBA