Working on updating some old code, and I've come across some code that I'm wondering if it would be better to update, or does it matter?
I need to grab some information from a table, so the first example (old) set the recordset to the table and then uses the "FindFirst" method with some criteria. (simplified for this example)
The second example (new) puts the table and all the criteria together as a normal SQL statement and pulls it that way.
Is there a difference or benefit to one way versus the other way?
It should be noted that this particular example is a single record, but sometimes I'm pulling multiple records and looping through them, if that makes a difference.
Thanks all!
I need to grab some information from a table, so the first example (old) set the recordset to the table and then uses the "FindFirst" method with some criteria. (simplified for this example)
Code:
Set rsMine = db.OpenRecordset("tblMine")
strSQL = "Part=" & PartNum
rsMine.FindFirst strSQL
If rsMine.NoMatch Then
'Some error message
Else
'Use the record that was found
End If
The second example (new) puts the table and all the criteria together as a normal SQL statement and pulls it that way.
Code:
strSQL = "SELECT TOP 1 FROM tblMine WHERE Part=" & PartNum
Set rsMine = db.OpenRecordset(strSQL)
If not rsMine.EOF Then 'Or should I use rsMine.RecordCount = 0
'Use the record that was found
End If
Is there a difference or benefit to one way versus the other way?
It should be noted that this particular example is a single record, but sometimes I'm pulling multiple records and looping through them, if that makes a difference.
Thanks all!