export fields into text file

Bioman

Registered User.
Local time
Today, 13:00
Joined
Feb 28, 2002
Messages
29
Hi! I tried this code to export fields from a SELECT but two lines doesn't work.

Public Sub ToTextFile()
Dim intFileNum As Integer
Dim strFileName As String
Dim strText As String
Dim db As DAO.Database
Dim rst As DAO.Recordset

intFileNum = FreeFile
strFileName = App.Path & "\" & Month(Date) & Day(Date) & Year(Date) & ".Log"

On Error Resume Next
Set db = CurrentDb
Set rst = db.OpenRecordset("Select [Name] From [Users]")
rst.MoveFirst
If Err <> 0 Then Exit Sub 'No Records

Do While Not rst.EOF
strText = strText & IIf(strText <> "", "+", "") & rst![Name]
rst.MoveNext
Loop

Open strFileName For Output As intFileNum
Print #intFileNum, strText
Close #intFileNum

Exit Sub



The line: If Err <> 0 Then Exit Sub 'No Records
and the line: strText = strText & IIf(strText <> "", "+", "") & rst![Name]
doesn't work. I use Access 2000. Any help would be appreciated!
 
Just to make sure

The new forum occasionally butchers < > symbols. That's what < and > are supposed to be: "Less than" and "Greater than".

I notice it's in both your lines that are failing, so I wanted to be sure that wasn't the problem right off the bat.
 
ok!

Thank you, it was the problem but I have two others problems:

I declare:
Dim db As DAO.Database
Dim rst As DAO.Recordset

but when I use the function, it cause an error who say the types are undefined!?! Is there a different way to declare this variables in Access 2000?

Thank you!
 
In any code module, go to Tools>References and make sure the DAO 3.6 reference is checked. To use DAO in Acc2k or later (which use ADO by default), you have to check that reference in any databases you're going to use DAO code in.
 

Users who are viewing this thread

Back
Top Bottom