Speed Up Loop Process

E

Ember

I have a report that OnClose the following code is set to run. Its purpose
is to check to see if the field "Print" is checked or not. If it is, I want
it unchecked. The code works fine, but takes forever as it has 5000 plus
records to loop through and that number will only grow. Is there anyway to
speed the process up?

Thanks!

Private Sub Report_Close()

strTableName = "tblFiles"
Set db = CurrentDb
Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)

With rst
Do Until .EOF
.MoveFirst
.FindFirst "[Print] = -1"
.Edit
.Fields("Print") = 0
.Update
.MoveNext
Loop
End With

rst.Close

Set db = Nothing
Set rst = Nothing

End Sub
 
D

Duane Hookom

Couldn't you run an udpate query like:

UPDATE tblFiles
SET [Print] = 0
WHERE [Print]=-1
 
E

Ember

Could this still be done in the OnClose property of the report?

Duane Hookom said:
Couldn't you run an udpate query like:

UPDATE tblFiles
SET [Print] = 0
WHERE [Print]=-1

--
Duane Hookom
MS Access MVP

Ember said:
I have a report that OnClose the following code is set to run. Its purpose
is to check to see if the field "Print" is checked or not. If it is, I
want
it unchecked. The code works fine, but takes forever as it has 5000 plus
records to loop through and that number will only grow. Is there anyway
to
speed the process up?

Thanks!

Private Sub Report_Close()

strTableName = "tblFiles"
Set db = CurrentDb
Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)

With rst
Do Until .EOF
.MoveFirst
.FindFirst "[Print] = -1"
.Edit
.Fields("Print") = 0
.Update
.MoveNext
Loop
End With

rst.Close

Set db = Nothing
Set rst = Nothing

End Sub
 
D

Duane Hookom

Try it.

Dim strSQL as String
strSQL = "UPDATE....."
DoCmd.RunSQL strSQL

After testing, you may want to SetWarnings = False then True.

--
Duane Hookom
MS Access MVP

Ember said:
Could this still be done in the OnClose property of the report?

Duane Hookom said:
Couldn't you run an udpate query like:

UPDATE tblFiles
SET [Print] = 0
WHERE [Print]=-1

--
Duane Hookom
MS Access MVP

Ember said:
I have a report that OnClose the following code is set to run. Its
purpose
is to check to see if the field "Print" is checked or not. If it is, I
want
it unchecked. The code works fine, but takes forever as it has 5000
plus
records to loop through and that number will only grow. Is there
anyway
to
speed the process up?

Thanks!

Private Sub Report_Close()

strTableName = "tblFiles"
Set db = CurrentDb
Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)

With rst
Do Until .EOF
.MoveFirst
.FindFirst "[Print] = -1"
.Edit
.Fields("Print") = 0
.Update
.MoveNext
Loop
End With

rst.Close

Set db = Nothing
Set rst = Nothing

End Sub
 
E

Ember

Duane - I have tried your suggestion. Now I am getting "Syntax error in
Update statement." Here is my code.

Private Sub Report_Close()
Dim strSQL As String
strSQL = "Update qryPortCheck"
DoCmd.RunSQL strSQL
End Sub

Thanks!
Ember

Duane Hookom said:
Try it.

Dim strSQL as String
strSQL = "UPDATE....."
DoCmd.RunSQL strSQL

After testing, you may want to SetWarnings = False then True.

--
Duane Hookom
MS Access MVP

Ember said:
Could this still be done in the OnClose property of the report?

Duane Hookom said:
Couldn't you run an udpate query like:

UPDATE tblFiles
SET [Print] = 0
WHERE [Print]=-1

--
Duane Hookom
MS Access MVP

I have a report that OnClose the following code is set to run. Its
purpose
is to check to see if the field "Print" is checked or not. If it is, I
want
it unchecked. The code works fine, but takes forever as it has 5000
plus
records to loop through and that number will only grow. Is there
anyway
to
speed the process up?

Thanks!

Private Sub Report_Close()

strTableName = "tblFiles"
Set db = CurrentDb
Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)

With rst
Do Until .EOF
.MoveFirst
.FindFirst "[Print] = -1"
.Edit
.Fields("Print") = 0
.Update
.MoveNext
Loop
End With

rst.Close

Set db = Nothing
Set rst = Nothing

End Sub
 
E

Ember

Thanks Duane, but I did more searching and found the following solution which
works great!

Private Sub Report_Close()
CurrentDb().Execute "qryProjCheck", dbFailOnError
End Sub

Ember

Duane Hookom said:
Try it.

Dim strSQL as String
strSQL = "UPDATE....."
DoCmd.RunSQL strSQL

After testing, you may want to SetWarnings = False then True.

--
Duane Hookom
MS Access MVP

Ember said:
Could this still be done in the OnClose property of the report?

Duane Hookom said:
Couldn't you run an udpate query like:

UPDATE tblFiles
SET [Print] = 0
WHERE [Print]=-1

--
Duane Hookom
MS Access MVP

I have a report that OnClose the following code is set to run. Its
purpose
is to check to see if the field "Print" is checked or not. If it is, I
want
it unchecked. The code works fine, but takes forever as it has 5000
plus
records to loop through and that number will only grow. Is there
anyway
to
speed the process up?

Thanks!

Private Sub Report_Close()

strTableName = "tblFiles"
Set db = CurrentDb
Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)

With rst
Do Until .EOF
.MoveFirst
.FindFirst "[Print] = -1"
.Edit
.Fields("Print") = 0
.Update
.MoveNext
Loop
End With

rst.Close

Set db = Nothing
Set rst = Nothing

End Sub
 

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