Cycle using Me.RecordsetClone

M

Maracay

Hi Guys

I use the code below to generate a text file on the disc, I used SET
rs=Recorset but because I read the whole file the information pass thru the
form and takes longer, someone said me to use Set rs = Me.RecordsetClone
instead to avoid this problem, I did it, is quick but is repeating the first
record in the whole file, I have research the topic but I haven’t find any
sequential read, all of then use find…, I will appreciate any help.

Thanks


FileHandle = FreeFile()
Open strFileName For Output As FileHandle
On Error GoTo Err_handler
Dim rs As Recordset
' Set rs = Recordset
Set rs = Me.RecordsetClone
rs.MoveFirst

Do Until rs.EOF


nCountLines = 4
AddedExpre1 = Expre1
strLine = Left(Mid((" " + Company), 2) & Space(60), 60)
Print #FileHandle, strLine
strLine = Left(Mid((" " + Fname) & (" " + LName), 2) & Space(60), 60)
Print #FileHandle, strLine
rs.MoveNext
Loop
Close #FileHandle
 
A

Allen Browne

The key problem is that it is reading Company, Fname, and LName from the
form (and hence just the current record) instead of from the recordset.
Before each field name you need to add:
rs!

This kind of thing:

'On Error GoTo Err_handler
Dim rs As Recordset
Dim iFileHandle As Integer
Dim strFileName As String

Set rs = Me.RecordsetClone
If rs.RecordCount = 0 Then
MsgBox "nothing to do"
Else

strFileName = "C:\SomeFolder\SomeFile.txt"
iFileHandle = FreeFile()
Open strFileName For Output As iFileHandle
rs.MoveFirst

Do Until rs.EOF
' nCountLines = 4
' AddedExpre1 = Expre1
strLine = Left(Mid((" " + rs!Company), 2) & Space(60), 60)
Print #iFileHandle, strLine
strLine = Left(Mid((" " + rs!Fname) & (" " + rs!LName), 2) &
Space(60), 60)
Print #iFileHandle, strLine
rs.MoveNext
Loop
End If

Set rs=Nothing
Close #iFileHandle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top