Re: VB-Script Counts of Recordsets ADODB MS Access
- From: "Bob Barrows" <reb01501@xxxxxxxxxxxxxxx>
- Date: Mon, 23 Jan 2012 08:32:52 -0500
Uwe Wiards wrote:
Hello,
i´m trying to read in VB-Script datas from a MS-Access database,
but... Into the table "Bestelldaten" are four test records, but
.recordcount told me "-1"
System: MS-XP and MS-Access 2002 SP3
Where are my mistakes?
SQL = "SELECT Bestelldaten.Nummer FROM Bestelldaten;"
strPfadDB = "c:\Testdb.mdb"
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" &
strPfadDB
Set Conn = CreateObject("ADODB.Connection")
Set Cmd = CreateObject("ADODB.Command")
conn.open strConn
cmd.ActiveConnection = conn
cmd.commandText=SQL
Set rs=CMD.Execute
If Not rs.EOF And Not rs.BOF Then
Msgbox "Count= " & rs.recordcount
Else
End If
Thanks an best regards
You need to use a different cursor type from the default read-only
forward-only cursor that does not support bookmarks or record count.
The easiest change is to change the cursor location of the recordset from
the default server-side cursor to a client-side cursor, because a
client-side cursor can only be a static cursor which does support bookmarks
and provides an immediate record count without moving to the last record.
There are two ways to change the cursor location:
1. change the connection object's CursorLocation property to adUseClient
before opening the recordset. This will cause the recordset to default to
client-side.
2. explicitly create the recordset object rather than using a variant
variable (rs), set its CursorLocation property to adUseClient, and use the
recordset's Open method to open it rather than the Command object's Execute
method.
In your particular situation, I would prefer method 1, since the explicit
Command object is not needed, given that you can use the Connection object's
Execute method instead:
conn.CursorLocation=3 'adUseClient
conn.open strConn
Set rs = conn.Execute(SQL,,1)
.
- References:
- VB-Script Counts of Recordsets ADODB MS Access
- From: Uwe Wiards
- VB-Script Counts of Recordsets ADODB MS Access
- Prev by Date: Re: VB-Script Counts of Recordsets ADODB MS Access
- Next by Date: UTF-8 problem
- Previous by thread: Re: VB-Script Counts of Recordsets ADODB MS Access
- Next by thread: UTF-8 problem
- Index(es):
Relevant Pages
|