DoCmd.Close command does not terminate form code execution

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I am experiencing a problem where a DoCmd.close command that has been coded
into a While Not loop does not terminate the execution of code where it
should.

Background:

I have created a custom progress bar on a form (Access 2003) that keeps track
of records that are being either archived or deleted, by way of a WHILE NOT
END OF FILE loop. The progress bar has a "Cancel" button on it which when
clicked, sets the value of a boolean variable named booCancel to "True". On
each iteration of the loop, the code checks the value of booCancel, and if
true records the cancel event to an audit log, closes and destroys the DAO
record set and closes the form.

Sample Code:

'Loop through records
While Not rs.EOF
'Check if process is canceled
If booCancel = True Then
Select Case intChoice
Case 1
Call AuditLog("Archive Cancel")
Case 2
Call AuditLog("Deletion Cancel")
End Select
rs.Close
Set rs = Nothing
DoCmd.Close
End If
rs.Edit

Problem:

The loop works as intended until the user clicks the Cancel button. When
this happens, the code executes all the code within the If statement
(including the DoCmd.close statement), and continues on to the rs.Edit
statement, which causes an "Error 91, Object Variable or With Block Variable
Not Set" error to occur as there is no record set to edit because the code
closed it.

An interesting point to note is that this error only occurs during run time.
When I step through the code in debug mode, the code executes perfectly; the
audit log is updated and the form closes without error.

I was under the impression that once DoCmd.close was called, all form level
code execution stopped, but this is apprently not the case here. Any insight
that can be offered here would be greatly appreciated.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/200705/1

.



Relevant Pages

  • Re: DoCmd.Close command does not terminate form code execution
    ... executing a Close does not immediately terminate the procedure that is running. ... END OF FILE loop. ... true records the cancel event to an audit log, ... code execution stopped, but this is apprently not the case here. ...
    (microsoft.public.access.modulesdaovba)
  • Re: I want to learn forth but...
    ... on each pass of the loop. ... deeper in the execution stack. ... faster than even a register bank of any real size. ...
    (comp.lang.forth)
  • Re: Reducing build-times for large projects.
    ... If the line before it executed, then the very next inline code has ... if your architecture does speculative execution and fetch. ... > THE FUNCTION THAT IS ALREADY IN CACHE! ... Loop unrolling "works" because you get to do N iterations worth of the ...
    (comp.lang.cpp)
  • Re: Running a background task
    ... background task that runs more or less forever, while normal execution ... entry On_String (String: in SideAB) ... It's generally not a good idea to reuse the identifier "String", since it hides the predefined type String, which will cause confusing error msgs if you ever try to use that type. ... end loop; ...
    (comp.lang.ada)
  • Re: MIT Scheme performance
    ... For example I have a loop like the one ... Regardless number of definitions the execution ... try to compile the defitions to a band and then to load it ... this is how to compile some definitions and how to produce ...
    (comp.lang.scheme)