Testing the State Property

If you choose not to rely on events, you can always test the object's State property. The State property returns a value that indicates the current status of the operation currently being carried out. For example, the following code segment tests the current state of a Connection object's Open operation.

cn.Open CurrentProject.Connection, ,

, adAsyncConnect

Do Until cn.State = adStateOpen

DoEvents

Loop

rs.Open "Invoices", cn

Not what we'd call a professional approach, but every programmer is different, and you might like to do such things. The State property can return the following values.

Constant

Value

Description

AdStateClosed

0

The object is closed.

AdStateOpen

1

The object is open.

AdStateConnecting

2

The object is connecting.

AdStateExecuting

4

The object is executing a command.

AdStateFetching

8

The object is retrieving rows.

0 0

Post a comment