-
May 3rd, 2006, 12:26 AM
#1
runtime error 3021
Hey all guru
I have a problem again. Why below code is doesnt work when i enter an ID which already exist in DB records.
Code:
Private Sub Command2_Click()
Dim name As String
Dim id As String
id = Me.stuff_id
If id = "" Then
MsgBox " You should enter an ID "
Else
RS.Close
RS.Open "Select * From table1 Where u_id='" & id & "'" , CN, adOpenDynamic, adLockOptimistic
If (RS.RecordCount > 0) Then
Me.stuff_id = RS("u_id")
Me.stuff_name = RS("u_name")
shp_ctrl.Show
Else
MsgBox "No user id"
End If
End If
Adodc1.Refresh
End Sub
if i make "if (RS.RecordCount < 0)" then it works but when enter a differnt ID number then have error.
I am very confused and stuck here.
Any help and idea please.
Regards
Last edited by jdavide; May 3rd, 2006 at 12:42 AM.
-
May 3rd, 2006, 01:42 AM
#2
Re: runtime error 3021
Sometimes even when you have records in the recordset the recordcount property shows it as -1. This is because the provider does not support bookmarks or absolute position. You should make it a habit to check EOF & BOF rather than recordcount.
In your case the recordset does not support recordcount property so you are getting -1 and thats why it works when you use less than sign. But even if there are no records in the recordset it will still return -1 as recordcount. So your code should check for EOF or BOF like this
Code:
If Not RS.BOF Then
Me.stuff_id = RS("u_id")
Me.stuff_name = RS("u_name")
shp_ctrl.Show
Else
MsgBox "No user id"
End If
-
May 3rd, 2006, 01:48 AM
#3
Re: runtime error 3021
Ali u r Wonderfullllll... I love you.......... it works
-
May 3rd, 2006, 01:56 AM
#4
Re: runtime error 3021
Originally Posted by jdavide
Ali u r Wonderfullllll... I love you.......... it works
I love you too.
-
October 27th, 2009, 12:19 AM
#5
Re: runtime error 3021
hii ali.... I m getting the runtime error when interfacing 8051 with pc.. hav written code in vb6.. the error is either BOF or EOF is true, or the current record
has been deleted. requested operation requires a current record..
Plz help me with it... Its very urgent
-
October 27th, 2009, 01:09 AM
#6
Re: runtime error 3021
I think you'd do better starting your own post, along with sample code that you're having a problem with.
Code:
' use Code Tags like this
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
|