Working with a recordset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table that has employee data in it. I want to look at each record
in the table and perform 'checks' on the data. If any one of these checks
fail, I want to move to the next record.

Here's an example:
stg = "select * from employees"
set rst = currentdb.openrecordset(stg)
rst.movefirst
do
check1
check2
check3
loop until rst.eof

If check1 fails, I don't want to go to check2, I want to go to the next
record in the recordset. I know I can use if statements, but I have a lot of
checks to perform and that could get ugly.

Any ideas?

Thanks,
J
 
What exactly is check1? Is it something that returns a boolean value?

If so, you need something like:

stg = "select * from employees"
set rst = currentdb.openrecordset(stg)
rst.movefirst
do
If check1 Then
If check2 Then
check3
End If
End If
loop until rst.eof
 
Check1 is another procedure that runs to verify certain information. I
declared a boolean variable (allOK) and if allOK is false based on the check1
procedure then I wanted it to stop and go to the next record in the
recordset. If allOK is true then I want it to go to the check2 procedure and
run through that. If allOK is false after check2 I want it to stop and go to
the next record in the recordset. If allOK is true, then I want it to go to
check3. I know I can use If statements, but I have a lot of 'checks' to run
and thought there might be a better way to run through the 'checks' and if at
anytime allOK was false, I could move to the next record (without having all
these nested IF statements).

Thanks.
 
thought of cases?

example.... (not using IDE so sorry if typos)

Set db = CurrentDB
strSQL = "SELECT * FROM employees"
Set rs = db.OpenRecordset(strSQL)
If rs.EOF = False then
Do Until rs.EOF = True
Select Case rs.Fields("Name").Value
Case "Bob"
'Do Something
Case "Jim"
'Do Something Else
End Select
rs.Movenext
Loop
Else
msgbox "no records!"
End If
Set rs = Nothing
Set db = Nothing
 
If allOK is true then I want it to go to the check2 procedure and
run through that. If allOK is false after check2 I want it to stop
and go to the next record in the recordset. If allOK is true, then I
want it to go to check3. I know I can use If statements, but I have a
lot of 'checks' to run and thought there might be a better way to run
through the 'checks' and if at anytime allOK was false, I could move
to the next record (without having all these nested IF statements).


This will do it without any nesting. Nesting is not any kind of bad
thing, unless it makes the code hard to maintain.

fAllOK = CheckOne()
If fAllOK Then fAllOK = CheckTwo()
If fAllOK Then fAllOK = CheckThree()
If fAllOK Then fAllOK = CheckFour()
'
' etc... as soon as a check returns false the
' rest of the chain is bypassed

If fAllOK Then MsgBox "All Checks OK"



Hope that helps


Tim F
 
Back
Top