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 / General 1 / November 2004

Tip: Looking for answers? Try searching our database.

runtime error 3021 'no current record' after it runs through the recordset?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Polly - 04 Nov 2004 22:33 GMT
I'm trying to write the results of a query, a name, ID number, and
date
out to a notepad .txt file to
print on a "legacy" printer.

I get the output from the first 2 "write" lines over the course of the
recordset, but get the 3021 error for
the third line, on the last record in the recordset.

(I did not include the input boxes code for the dates range because
that's working.)
I tried Debug.Print rs1.Fields(8).NAME and the field name matches
what's
typed into the SQL statement.

Also, I tested for end of file with a msg box:
If rs1.EOF Then
   MsgBox "end of file"
End If

and it returned
"end of file"

If someone could point me in the right direction, I would appreciate
it!

Polly
cavavite(removethis)@hotmail.com

Private Sub cmdRunLblsOutput_Click()
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim strSQL As String

'++++++++++++++++ Report Variables
Dim strtFn, strtLn, strFnLn, strPID As String

Set db = CurrentDb
strSQL = ""   'initialize strSQL value

'SQL statement
strSQL = "SELECT qselbsln.pid, fn,ln,CASID, "
strSQL = strSQL & "GRPCD, MaxOftubeLogid, " '
strSQL = strSQL & "FAMID, MEMID, dPossibleDraw " 'tblSelectLabels.
strSQL = strSQL & "FROM qselbsln, tblSelectLabels INNER JOIN
qmaxTubeId_Pid ON "
strSQL = strSQL & "tblSelectLabels.PID = qmaxTubeId_Pid.pid "
strSQL = strSQL & "WHERE ((tblSelectLabels.dPossibleDraw) between #"
strSQL = strSQL & dBeg & "# and #" & dEnd & "#) "
strSQL = strSQL & "and ((tblSelectLabels.chkSelectForLabel)=Yes) and "
strSQL = strSQL & "(tblSelectLabels.PID = qselBsln.PID) "

Set rs1 = db.OpenRecordset(strSQL)

Debug.Print rs1.Fields(8).NAME     '----------->this works
rs1.MoveFirst

MsgBox rs1!dPossibleDraw           '-------------> no message box
comes up

Open "c:\possibleDraws\PossDrws.txt" For Output As #1

Do Until rs1.EOF

   rs1.MoveNext

   Write #1, strFnLn
   Write #1, strPID
   If rs1.EOF Then
       MsgBox "end of file"
   End If
   Write #1, rs1![dPossibleDraw]
Loop

Close #1
MsgBox "done"
Allen Browne - 05 Nov 2004 03:13 GMT
You need the MoveNext *after* you have written the line, immediately before
the Loop line. After the MoveNext you may be at EOF.

Could you achieve the same thing by saving the query, and using just:
   Docmd.TransferText acExportDelim, , "Query1", "C:\MyFile.txt"

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> I'm trying to write the results of a query, a name, ID number, and
> date
[quoted text clipped - 72 lines]
> Close #1
> MsgBox "done"
Polly - 08 Nov 2004 18:11 GMT
Dear Allen,
Thank you. That did it.
Thanks for the suggestion to use a docmd statement, but I need to
format the output to the sneaker-net printer. The output was just to
see if I could get it to write to an external file first. If I have
trouble with the formatting or function I'm going to use, I'll be
posting that code, too.

Polly

> You need the MoveNext *after* you have written the line, immediately before
> the Loop line. After the MoveNext you may be at EOF.
[quoted text clipped - 78 lines]
> > Close #1
> > MsgBox "done"
 
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.