i am using ADODB to connect an access database to my forms. i have the folloing code which searches the database table for a barcode. it searches and displays correctly, until you put in a non existant barcode, then it comes up with error 3021. eof bof error. it highlights the line
text1.text = RS!Barcode

however, if i move the lines
text1.text = RS!Barcode
text2.text = RS!Name
below the if statement for checking eof and bof, then not having the barcode in the database will show the "record not found" messege box, then display the previous error. however, it will not display the text in the boxes if the barcode is correct.

here is the code, any help is well apprecciated

Private Sub cmdFind_Click()

Dim tr As String

RS.MoveFirst
tr = InputBox("Enter Barcode", "Find")
If tr > 0 Then
tr = "barcode='" & tr & "'"
RS.Find tr

Text1.Text = RS!Barcode
Text2.Text = RS!Name

Else

If RS.EOF Or RS.BOF = True Then
MsgBox "Record was not Found", vbInformation + vbOKOnly, "No Match"

End If
End If
End Sub
Member Avatar

You should be able to fix this by checking for the existence of records before doing anything else.

In psuedo

tr = form input

move to beginning of recordset

find tr

if not rs.eof or not rs.bof then
display record
else
error message
end if

Cheers

Andy

Hey nicentral,

Nice Psuedo code, it's been years since I last saw that (University)!

However I think you meant to put an "AND" in here:
if not rs.eof or not rs.bof then

or maybe

If not (rs.eof or rs.bof) then

I hate it when I get caught in these little "Logic Traps"

Happy Coding

Yomet

Member Avatar


However I think you meant to put an "AND" in here:

Good call Yomet! That's what happens when you don't COMPLETELY think something through before sending it off.

Cheers!

Andy