Hey everybody,
I have question about do while loops. I am currently running a loop to check for values in a table using a DAO recordset against another DAO recordset (See code below). However, I am receiving some problematic returns. On some of the matches a count of 1 is returned. Others are returning a count of zero. However if a count of zero is returned the Invset still returns values... If one value is returned the Do While Loop should process data and return a correct count of 1. If a count of more than 1 is returned then the correct number of matches is returned. However, if no values are found then the default value of count should return a zero - but why am I still getting Invset field values in the message box? Any ideas or am I just going crazy...
Thanks,
jbehrne
'recset is a DAO recordset passed to the function
'Invset is a DAO recordset
'sqlString is a string
'count is an integer
count = 0
sqlString = "SELECT * FROM InfoTable WHere InfoTable.Amt = " & recset![Amount] & " InfoTable.InvoiceNumber = '" & recset![Inv] & "'"
Set Invset = CurrentDb.OpenRecordset(sqlString, dbOpenDynaset, dbSeeChanges, dbOptimistic)
If Invset.EOF = True Then
Invset.Close
Exit function
Else
Invset.MoveFirst
Do While Invset.EOF = False
count = count + 1
Invset.MoveNext
Loop
End If
MsgBox "Returned " & count & " matching records from InfoTable." & vbcrlf & "Amount: " & Invset![Amount] & " and Invoice Number: " & Invset![Inv]
Invset.close
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
I have question about do while loops. I am currently running a loop to check for values in a table using a DAO recordset against another DAO recordset (See code below). However, I am receiving some problematic returns. On some of the matches a count of 1 is returned. Others are returning a count of zero. However if a count of zero is returned the Invset still returns values... If one value is returned the Do While Loop should process data and return a correct count of 1. If a count of more than 1 is returned then the correct number of matches is returned. However, if no values are found then the default value of count should return a zero - but why am I still getting Invset field values in the message box? Any ideas or am I just going crazy...
Thanks,
jbehrne
'recset is a DAO recordset passed to the function
'Invset is a DAO recordset
'sqlString is a string
'count is an integer
count = 0
sqlString = "SELECT * FROM InfoTable WHere InfoTable.Amt = " & recset![Amount] & " InfoTable.InvoiceNumber = '" & recset![Inv] & "'"
Set Invset = CurrentDb.OpenRecordset(sqlString, dbOpenDynaset, dbSeeChanges, dbOptimistic)
If Invset.EOF = True Then
Invset.Close
Exit function
Else
Invset.MoveFirst
Do While Invset.EOF = False
count = count + 1
Invset.MoveNext
Loop
End If
MsgBox "Returned " & count & " matching records from InfoTable." & vbcrlf & "Amount: " & Invset![Amount] & " and Invoice Number: " & Invset![Inv]
Invset.close
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations