Trouble aborting a loop

  • Thread starter pubdude2003 via AccessMonster.com
  • Start date
P

pubdude2003 via AccessMonster.com

I have seen a number of posts on this issue and I seem to have it coded
correctly but it just won't stop.

Static sfRunning As Boolean
sfRunning = True

Dim ID As Integer
Dim FileName As String
Dim SQLStmt As String
Dim SQLStmt2 As String
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim db As DAO.Database
Dim RecordN As Integer
Dim counter1 As Integer

RecordN = 0

Set db = CurrentDb()

SQLStmt = "SELECT ID, FileName"
SQLStmt = SQLStmt & " FROM query1"
SQLStmt2 = "SELECT tblDirectory.FileName FROM tblDirectory INNER JOIN
Query4 ON tblDirectory.JustFile = Query4.FirstOfJustFile"

Set rs = db.OpenRecordset(SQLStmt)
Set rs2 = db.OpenRecordset(SQLStmt2)

rs.MoveLast
counter1 = rs.RecordCount
rs.MoveFirst

DoEvents
Do Until rs.EOF = True
DoEvents
If sfRunning = FalseThen
Exit Do
DoEvents
End If

RecordN = RecordN + 1
Me.Text38 = "Printing file " & (RecordN) & " of " & counter1
Requery
If rs!FileName = rs2!FileName Then
OpenAcrobat
PrintPDFDoc rs2!FileName
DoEvents
rs2.MoveNext
End If
OpenAcrobat
PrintPDFDoc2 rs!FileName

rs.MoveNext
DoEvents

Loop

Code to stop sfRunning
Sub cmdStart_Click()

With cmdStart
sfRunning = False
DoEvents
cmdStart.Caption = "Stopping"
DoEvents
End With

End Sub

Any insights would be appreciated
 
D

Douglas J. Steele

What's the Requery statement there for? I think that may be your culprit.
 
P

pubdude2003 via AccessMonster.com

Thanks Douglas, yeah just as I was posting it I thought it might be the bug
too. Tested and it's not the problem. It's just there to refresh a text box
What's the Requery statement there for? I think that may be your culprit.
I have seen a number of posts on this issue and I seem to have it coded
correctly but it just won't stop.
[quoted text clipped - 66 lines]
Any insights would be appreciated
 
P

pubdude2003 via AccessMonster.com

BTW, thanks for that web scraper sample you posted on your site. I should be
able to run my golf pool this season with one or two mouse clicks... hurray!
Thanks Douglas, yeah just as I was posting it I thought it might be the bug
too. Tested and it's not the problem. It's just there to refresh a text box
on the form.
What's the Requery statement there for? I think that may be your culprit.
[quoted text clipped - 3 lines]
 
D

Douglas J. Steele

Just noticed this, presumably in a sub:

Static sfRunning As Boolean

cmdStart_Click doesn't see variables that are defined in other routines.

There's really no need for Static: just declare the variable at the
beginning of the module, before the first function or sub:

Private sfRunning As Boolean

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


pubdude2003 via AccessMonster.com said:
Thanks Douglas, yeah just as I was posting it I thought it might be the
bug
too. Tested and it's not the problem. It's just there to refresh a text
box
What's the Requery statement there for? I think that may be your culprit.
I have seen a number of posts on this issue and I seem to have it coded
correctly but it just won't stop.
[quoted text clipped - 66 lines]
Any insights would be appreciated
 
P

pubdude2003 via AccessMonster.com

Thanks very much Douglas, that got it... appreciate your help!
Just noticed this, presumably in a sub:

Static sfRunning As Boolean

cmdStart_Click doesn't see variables that are defined in other routines.

There's really no need for Static: just declare the variable at the
beginning of the module, before the first function or sub:

Private sfRunning As Boolean
Thanks Douglas, yeah just as I was posting it I thought it might be the
bug
[quoted text clipped - 9 lines]
 

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