halting VB program execution until OS finishes 
Author Message
 halting VB program execution until OS finishes

Hi,

I'm trying to get my VB program to wait until a previous
command has finished executing before it goes ahead and
executes the next command line. It's running within Access
and it deals with retrieving records from a database
through sql statememnts.
Here's the portion of the code and I've marked where the
program halting needs to happen:

        Set db = CurrentDb()
        sql = "SELECT DocumentID, DocumentName FROM
tblMyDocuments"
        sql = sql & " WHERE Current = true;"
        Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
        (!!!!!it is here that I need to have a command
that halts the program execution until all records are
placed in the recordset!!!!!)

        If Not rs.EOF Then
            rs.MoveFirst
            counter = 0
            While counter < rs.RecordCount
                'Preview/Print Document command here
        etc, etc.

Does anyone have any idea as to what I can do here??

Greately appreciate your help,

Ian.



Thu, 16 Dec 2004 15:43:03 GMT  
 halting VB program execution until OS finishes
Hi Ian,

Looking at the code you gave it would appear that you are finding that
rs.RecordCount is returning a value of 1 thus stopping correct execution of
your program. The problem isn't in that the code is continuing before all
records are in the recordset its that the Recordeset hasn't been filled.
After opening a Recordset using "Set rs=db.OpenRecordset" you must populate
that recordset with the command "rs.MoveLast" . Insert "rs.MoveLast" after
the Set rs...... line and I think that will solve your problem.

HTH
David


Quote:
> Hi,

> I'm trying to get my VB program to wait until a previous
> command has finished executing before it goes ahead and
> executes the next command line. It's running within Access
> and it deals with retrieving records from a database
> through sql statememnts.
> Here's the portion of the code and I've marked where the
> program halting needs to happen:

>         Set db = CurrentDb()
>         sql = "SELECT DocumentID, DocumentName FROM
> tblMyDocuments"
>         sql = sql & " WHERE Current = true;"
>         Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
>         (!!!!!it is here that I need to have a command
> that halts the program execution until all records are
> placed in the recordset!!!!!)

>         If Not rs.EOF Then
>             rs.MoveFirst
>             counter = 0
>             While counter < rs.RecordCount
>                 'Preview/Print Document command here
>         etc, etc.

> Does anyone have any idea as to what I can do here??

> Greately appreciate your help,

> Ian.



Fri, 17 Dec 2004 05:45:20 GMT  
 halting VB program execution until OS finishes
Don't use RecordCount to loop through a recordset. It may change! Use
    Do While Not rs.EOF
instead. It is much safer and you won't have to do a MoveLast before hand.
--
Simon Jones
MillStream Designs Ltd
Independent IT Consultants


Quote:
> Hi Ian,

> Looking at the code you gave it would appear that you are finding that
> rs.RecordCount is returning a value of 1 thus stopping correct execution
of
> your program. The problem isn't in that the code is continuing before all
> records are in the recordset its that the Recordeset hasn't been filled.
> After opening a Recordset using "Set rs=db.OpenRecordset" you must
populate
> that recordset with the command "rs.MoveLast" . Insert "rs.MoveLast" after
> the Set rs...... line and I think that will solve your problem.

> HTH
> David



> > Hi,

> > I'm trying to get my VB program to wait until a previous
> > command has finished executing before it goes ahead and
> > executes the next command line. It's running within Access
> > and it deals with retrieving records from a database
> > through sql statememnts.
> > Here's the portion of the code and I've marked where the
> > program halting needs to happen:

> >         Set db = CurrentDb()
> >         sql = "SELECT DocumentID, DocumentName FROM
> > tblMyDocuments"
> >         sql = sql & " WHERE Current = true;"
> >         Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
> >         (!!!!!it is here that I need to have a command
> > that halts the program execution until all records are
> > placed in the recordset!!!!!)

> >         If Not rs.EOF Then
> >             rs.MoveFirst
> >             counter = 0
> >             While counter < rs.RecordCount
> >                 'Preview/Print Document command here
> >         etc, etc.

> > Does anyone have any idea as to what I can do here??

> > Greately appreciate your help,

> > Ian.



Fri, 17 Dec 2004 17:15:49 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Pause program execution until other application finishes

2. Help Pausing VB4 execution until DOS app finishes (Not Windows App)

3. Halt program until Shell completes

4. Msgbox halts program execution of timers

5. Calling an external program (and waiting until it's finished)

6. Waiting until external program finished to continue processing

7. How can I wait until a program finishes ?

8. Determine whether a external program (process) has finished execution successfully

9. VB don't Recognize if a execution of a .BAT file was finished

10. Halting execution of Access97

11. Reading param values halts ActiveX execution

12. Halting Code Execution while form is active

 

 
Powered by phpBB® Forum Software