 |

01-19-2003, 10:51 PM
|
|
Regular
|
|
Join Date: Oct 2002
Location: India
Posts: 80
|
|
RecordCount Function Problem.w
|
I am using the RecordCount function to catch the EOF BOF / NO record exist error
using the following statement.
if rs.RecordCount=0 then Exit Sub
But Sometimes I find that the program still gives the EOF BOF/no record error. When I debug the statement I found that VB is counting the records at -1 through there were no records exist.
I had to modified my statement as
if rs.RecordCount <=0 then Exit Sub
I am confused how can VB count the records as -1
PLS HELP.
rgds,
Dennis.
|
|

01-19-2003, 11:49 PM
|
 |
C# Lover
* Expert *
|
|
Join Date: Jan 2002
Location: 00-80-C8-C3-2E-52
Posts: 1,899
|
|
You need to specify the cursor position and locktype. Here's an example:
Code:
RS.Open strSQL, adpCon, adOpenStatic, adLockOptimistic, 1
If you're using DAO, then you need to move to the end of the recordset before accessing the RecordCount property.
|
__________________
"Man is still the best computer we can put aboard a spacecraft...and the only one that can be mass produced with unskilled labor." - Wernher von Braun
|

01-20-2003, 01:07 AM
|
|
Centurion
|
|
Join Date: Feb 2002
Location: Indonesia
Posts: 170
|
|
|
or u can use this, when you open your recordset
RS.Open strSQL, adpCon, adOpenKeyset, adLockOptimistic, AdCmdText
if u use adOpenforward, you need to MoveFirst and the MoveLast to know RecordCount
|
|

01-20-2003, 07:22 AM
|
 |
Disillusioned Code Poet
Retired Moderator * Guru *
|
|
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
|
|
|
Sorry, joe77s, that is incorrect. If you MoveLast on an adOpenForwardOnly recordset, you then can no longer access any of the other fields. The RecordCount property of an ADO recordset (unlike DAO) will be accurate for a bookmarkable recordset, without needing to traverse it fully first. Note that server-side cursors and forward-only and dynamic (hope I got that list right) recordsets are not bookmarkable and will always return a RecordCount of -1.
|
__________________
Laura
Ita erat quando hic adveni.
|

01-20-2003, 10:10 PM
|
|
Regular
|
|
Join Date: Oct 2002
Location: India
Posts: 80
|
|
|
Hi Rezner, Joe & Icebb
Thanks a lot for taking part in the discussion. I am opening the recordset as follows.
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set rs1 = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
Set rs3 = New ADODB.Recordset
cn.Open "DSN=payroll;uid=;pwd=;"
rs1.Open "select * from acctyear where yr = '" & frmEnterSal.cmbYear.Text & "'", cn, adOpenDynamic, adLockOptimistic
rs.Open "select * from salary where yr = '" & frmEnterSal.cmbYear.Text & "'order by empno", cn, adOpenDynamic, adLockOptimistic
rs2.Open "select * from emp where status ='Active' order by empno", cn, adOpenKeyset, adLockOptimistic
rs3.Open "emp", cn, adOpenKeyset, adLockOptimistic, adCmdTable
While Not rs2.EOF
cmbEmpNo.AddItem rs2!empno
rs2.MoveNext
Wend
DisableButtons "D"
rs1.MoveLast
txtYear.Text = rs1!yr
If rs1.RecordCount = 0 Then Exit Sub
If rs2.RecordCount = 0 Then Exit Sub
If rs.RecordCount = 0 Then Exit Sub
ShowData
End Sub
Please tell me how I should have opened the recordset in the above code.
Regards,
Dennis.
|
|

01-21-2003, 06:05 AM
|
 |
Disillusioned Code Poet
Retired Moderator * Guru *
|
|
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
|
|
Before your cn.Open statement, add the line
Code:
cn.CursorLocation = adUseClient
and change all your adOpenDynamic constants to adOpenStatic.
If you want to check to see if a given recordset is bookmarkable, and thus would return a valid recordcount, you can use
Code:
YourRS.Supports(adBookmark)
If this returns True, then you will get a valid RecordCount.
|
__________________
Laura
Ita erat quando hic adveni.
|

01-21-2003, 08:08 AM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
And all of this will be moot if you check for an empty recordset correctly with
If rs.BOF And rs.EOF
instead of
If rs1.RecordCount = 0
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

01-21-2003, 09:45 PM
|
|
Regular
|
|
Join Date: Oct 2002
Location: India
Posts: 80
|
|
|
Thanks friends for you valuable suggestions,
rgds,
Dennis
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|