"J Bailey" <(E-Mail Removed)> wrote in
news:072c01c37eeb$d8fadf40$(E-Mail Removed):
> rsTimeoff.MoveFirst
This line does nothing except raise an error if the recordset is empty:
just junk it.
> Do Until (rsTimeoff!us_agentSSN = strGlobalSSN And _
> rsTimeoff!us_Date = dtmJobDate) _
> Or (rsTimeoff.EOF = True)
This is a complex boolean expression, and while it may be correct, and it
might even mean something to you now, you'll stare at it in eighteen months
and wonder what the hell you were trying to do. You would be much better
served by splitting it up, and at the same time avoid the error:
' first test is the EOF, so you don't even get into
' the loop if it's an empty recordset
Do While Not rsTimeOff.EOF
' okay, now look for test conditions and exit
' when they are both met
If rsTimeOff!us_agentSSN = strGlobalSSN And _
rsTimeOff!us_Date = dtmJobDate Then
Exit Do
End If
> rsTimeoff.MoveNext
> Loop
> I
> have written code very similar to this in the past with
> VB6 and it works just fine.
The reason it fails here and works in VB6 is that VB will short-circuit
boolean expressions: as soon as one part of an OR list is true it stops
testing the rest, and vice versa for AND lists. VBA is not so clever,
however, and tries to evaluate each little bit regardless of whether it
will affect the outcome. There are advantages and disadvantages of each
approach, but you just need to know what is going to happen.
Incidentally, I notice that this loop does absolutely nothing except to see
if there is a row that meets the criterion. This might be because you
wanted to save space in the message (good idea!); but if you really only
want to test for that then you can do it with less grief in one go:
strSQL = "SELECT COUNT(*) AS NumRecs " & _
"FROM us_TimeOff " & _
"WHERE us_agentSSN = '" & strGlobalSSN & "' " & _
" AND us_Date = Format(dtmJobDate, strSQLDtFormat)
rs.Open strSQL, ConnStr6, adOpenForwardOnly, adLockPessimistic
If rs!NumRecs = 0 Then
' there is no record there
Else
' there is at least one
End If
Hope that helps
Tim F
|