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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with retrieving value from recordset

Status
Not open for further replies.

nikdiva

Programmer
Jul 27, 2001
17
US
Hi all, I am trying to use the following code to return a value to a query:

Function CheckQ102(ProvString As String)
Dim db As Database
Dim rst As DAO.Recordset
Dim fld As String

Set db = CurrentDb

Set rst = CurrentDb.OpenRecordset("MissingProv")
rst.MoveFirst
fld = rst.Fields("ProvCode").Value

Do While Not rst.EOF
If fld = ProvString Then
CheckQ102 = "N"
Else
CheckQ102 = "Y"
End If
rst.MoveNext
fld = rst.Fields("ProvCode").Value
Loop

End Function

I am getting an error message when I run the query saying "Run time error 3021 - No current record"

What am I doing wrong?

Nikki Wright
Database Specialist
"Everyday is a winding road, I get a little bit closer to feelin' fine"
 
Whatever "MissingProv" is, it's not returning any records. Have you opened the same query/table in datasheet view and verified that it's not empty?
 
Yes, it is a table that I created and populated with data.
 

Do While Not rst.EOF
If fld = ProvString Then
CheckQ102 = "N"
Else
CheckQ102 = "Y"
End If
rst.MoveNext
''''- how do you know you are not at end of file here?????
fld = rst.Fields("ProvCode").Value
Loop
 
check for rst.eof and rst.bof

In which case you have no records in the recordset and need to act accordingly.

rollie@bwsys.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top