Bug in x = y, how can this be?

  • Thread starter Thread starter MB
  • Start date Start date
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
 
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
 
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.
 
Back
Top