Bug in x = y, how can this be?

M

MB

I have a piece of code I am working on in a mdb (front end for a SQL
database)

----------------------------------------------
Set rst = db.OpenRecordset(SQLStmt, dbOpenSnapshot)
numrecs = rst.RecordCount()
Select Case numrecs
Case Is = 1
rst.MoveFirst
Do Until rst.EOF = True
MsgBox rst("invoice number")
rst.MoveNext
Loop
Case is > 1
do other stuff
end select
-------------------------------------------------

Examining rst.RecordCount() in the debugger, it is actually 11 as evidenced
by the loop executing 11 times, but numrecs is 1 , also as evidenced by the
fact that the loop executes at all.

I have another similar situation, where the variable on the left does not
equal the right after the assignment. I realize my memory (the biological
one) is toast, but am I missing something here?

Thanks in advance,

Marc Berman
 
K

Ken Snell [MVP]

The recordset will not contain all the records when it's initially opened.
You must force it to get all the records before you check its record count.

Set rst = db.OpenRecordset(SQLStmt, dbOpenSnapshot)
rst.MoveLast
numrecs = rst.RecordCount()
rst.MoveFirst
Select Case numrecs
Case Is = 1
rst.MoveFirst
Do Until rst.EOF = True
MsgBox rst("invoice number")
rst.MoveNext
Loop
Case is > 1
do other stuff
end select
 
M

Mike Painter

MB said:
I have another similar situation, where the variable on the left does
not equal the right after the assignment. I realize my memory (the
biological one) is toast, but am I missing something here?

Where are you using "x = y"
if in
dim x, y
y = 1
x = y
msgbox x

you don't get one there is a problem.

However it is possible in many cases to have Access evaluate
x = y and return True or False

It would be nice to not allow this but I suspect it's to late to impliment
it in BASIC.
 

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