-
February 9th, 2011, 05:55 AM
#1
runtime error 3021
runtime error 3021 (either BOF or EOF is true, or the current record
has been deleted. requested operation requires a current record)
heres my code
Code:
Dim rs As ADODB.Recordset
Dim bData() As Byte
Private Sub Form_Load()
MSComm1.PortOpen = True
connect
Set rs = New ADODB.Recordset
rs.Source = "Users"
rs.ActiveConnection = cn
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.Open
End Sub
Private Sub showRecord()
If rs.EOF Or rs.BOF Then Exit Sub
ReDim bData(rs.Fields("photo").ActualSize)
bData = rs.Fields("photo").Value
szfile = App.Path & "\tempPic.tmp"
Open szfile For Binary Access Write As #1
Put #1, , bData
Close #1
Image1.Picture = LoadPicture(szfile)
Label1.Caption = rs.Fields("Studentno")
Label3.Caption = rs.Fields("Surname")
Label4.Caption = rs.Fields("Firstname")
Label5.Caption = rs.Fields("Middlename")
Label6.Caption = rs.Fields("College")
Label7.Caption = rs.Fields("Course")
Label8.Caption = rs.Fields("Yrsec")
End Sub
Private Sub MSComm1_OnComm()
Text1.Text = Clear
Dim strinput As String
strinput = MSComm1.Input
Text1.Text = Text1.Text & strinput
Label9.Caption = Format$(Now, "m/d/yy h:mm Am/Pm")
End Sub
Private Sub Text1_Change()
Dim strSQL As String
rs.Close
strSQL = "SELECT * "
strSQL = strSQL & "FROM users "
strSQL = strSQL & "WHERE Rfid = '" & Text1.Text & "'"
rs.Open strSQL, GetConnString, adOpenForwardOnly, adLockReadOnly
If Text1.Text = rs.Fields("Rfid") Then <----- error is here
showRecord
Else
Form1.Show
End If
End Sub
Private Function GetConnString() As String
GetConnString = "Provider=Microsoft.jet.oledb.4.0;Data Source=" & App.Path & "\RegID.mdb"
End Function
-
February 9th, 2011, 07:51 AM
#2
Re: runtime error 3021
The error is basically telling you that the query returned no results and you are trying to read from something that is not there.
Always use [code][/code] tags when posting code.
-
February 9th, 2011, 08:14 AM
#3
Re: runtime error 3021
yes thats true.. but if ididnt return any result, isnt it must go to the else then open form1?? because it is in if clause
-
February 9th, 2011, 10:21 AM
#4
Re: runtime error 3021
Originally Posted by killua14
yes thats true.. but if ididnt return any result, isnt it must go to the else then open form1?? because it is in if clause
Code:
If Text1.Text = rs.Fields("Rfid") Then
Will always return an error when there are no records in your recordset. Basically you are trying to compare the value in text1 to something that does not exist and that results in an error.
You must either check the BOF EOF status first or check the recordcount property. You can only read the fields of the RS when there is a valid record currently selected.
Always use [code][/code] tags when posting code.
-
February 10th, 2011, 03:11 AM
#5
Re: runtime error 3021
so how to that?? checking the BOF and EOF?? thxs in advance
-
February 10th, 2011, 09:25 AM
#6
Re: runtime error 3021
By using an If Then block of course. BOF and EOf are both properties of the RS object. There are literally 1,000s of examples plastered all over the internet.
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|