Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to find an item in a table and report back if it is found.

Status
Not open for further replies.

cal555

Programmer
May 5, 2006
71
US
Hi,
I am trying to find an item in a table and report back if it is found. I am workin gin Access 2003, and if possable I want to stick to using ADO. The code I have below I thought would do it, but it does not work. With this set up I get an error saying that I am either at the BOF or EOF or the current record has been deleted. If someone can tell me what I am doing wrong I would appreciate it.
Thank you

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL1 As String

strSQL1 = "Select * from Orders Where order_num = '" & Text1 & "'"

Set cn = CurrentProject.Connection

Set rs = New ADODB.Recordset

rs.Open strSQL1, cn

If rs!order_num = Null Then
Text3 = "the item is not in the table"
Else
Text3 = "the item is not in the table"
End If

End Sub
 



Hi,
Code:
rs.Open strSQL1, cn

On error resume next

rs.movefirst

If err.number = 0 Then
  Text3 = "the item is in the table"
Else
  Text3 = "the item is not in the table"
End If

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Try testing for .Bof/.Eof

[tt]If ((Not rs.Bof) And (Not rs.Eof)) Then
Text3 = "the item is found in the table"
Else
Text3 = "the item is not in the table"
End If[/tt]

Also, since this is within Access, you might perhaps try your luck in one of the seven Access fora on the site...

Roy-Vidar
 
Thasnk You
Itryed what you said using the EOF and that worked.
Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top