K
keithius
I'm having an unusual problem with DAO and VBA in Word 2000. Here's the
problem code:
set myRecord = myDatabase.OpenRecordset(someQuery)
"myDatabase" is an open database connection to an Access database file
(mdb file), "myRecord" is a Recordset object, and "someQuery" is an SQL
query string; e.g. "select * from thisTable where thisField=SomeValue"
The problem is, if "someQuery" returns 0 (zero) rows, then myRecord
isn't "set" - it remains uninitialized. Later on in the code, a test
like this is used:
do while myRecord.EOF = False
' do something
loop
This causes a problem in Word 2000 (but not later versions of Word)
because "myRecord" is not set, so you get a "object variable or with
block variable not set" error.
My question is this: is the behavior of "OpenRecordset" different under
Word 2000's VBA? Or have I been wrong all this time in assuming that if
the query passed to OpenRecordset returned 0 (zero) rows, it would at
least return an empty (i.e. EOF=True) recordset? Or is this maybe just
a strange problem with a particular installation of Word/VBA/JET/DAO?
problem code:
set myRecord = myDatabase.OpenRecordset(someQuery)
"myDatabase" is an open database connection to an Access database file
(mdb file), "myRecord" is a Recordset object, and "someQuery" is an SQL
query string; e.g. "select * from thisTable where thisField=SomeValue"
The problem is, if "someQuery" returns 0 (zero) rows, then myRecord
isn't "set" - it remains uninitialized. Later on in the code, a test
like this is used:
do while myRecord.EOF = False
' do something
loop
This causes a problem in Word 2000 (but not later versions of Word)
because "myRecord" is not set, so you get a "object variable or with
block variable not set" error.
My question is this: is the behavior of "OpenRecordset" different under
Word 2000's VBA? Or have I been wrong all this time in assuming that if
the query passed to OpenRecordset returned 0 (zero) rows, it would at
least return an empty (i.e. EOF=True) recordset? Or is this maybe just
a strange problem with a particular installation of Word/VBA/JET/DAO?