473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Count in Access

Okay, I'm confused. The code below produces no errors and prints -1
for the RecordCount. I run it on a local Access DB. I ran the query
in Access and it returns correctly one field with one row representing
the Count...

However the Response.Write(numAvailServers) statement prints nothing !
There must be at least one record or it wouldn't go inside the
If....What am I missing here...

'Get number of available servers
strSQLquery = "SELECT COUNT(*) As resF FROM Server "
strSQLquery = strSQLquery & "WHERE server_status=1"

set rs2 = conn.Execute(strSQLquery)
Call ErrorVBScriptReport("Exuecute:" & sqrSQLQuery)
Call ErrorADOReport("Exuecute:" & sqrSQLQuery, conn)

If rs2.EOF = false Then
numAvialServers = rs2.Fields("resF")
Response.Write(numAvailServers)
Response.Write(rs2.RecordCount)
End If
Nov 12 '05 #1
5 2172
Are you creating the object first ...

Set rs2 = Server.CreateObject("adodb.recordset")

Set rs2 = conn.Execute(strSQLquery)
numAvialServers = rs2.Fields("resF")

--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com
"Stefan" <st****@dragolov.com> wrote in message news:89**************************@posting.google.c om...
Okay, I'm confused. The code below produces no errors and prints -1
for the RecordCount. I run it on a local Access DB. I ran the query
in Access and it returns correctly one field with one row representing
the Count...

However the Response.Write(numAvailServers) statement prints nothing !
There must be at least one record or it wouldn't go inside the
If....What am I missing here...

'Get number of available servers
strSQLquery = "SELECT COUNT(*) As resF FROM Server "
strSQLquery = strSQLquery & "WHERE server_status=1"

set rs2 = conn.Execute(strSQLquery)
Call ErrorVBScriptReport("Exuecute:" & sqrSQLQuery)
Call ErrorADOReport("Exuecute:" & sqrSQLQuery, conn)

If rs2.EOF = false Then
numAvialServers = rs2.Fields("resF")
Response.Write(numAvailServers)
Response.Write(rs2.RecordCount)
End If

Nov 12 '05 #2
RecordCount Property of an ADO Recordset may gives -1 (to indicate a
non-empty Recordset) rather than the actual tuple count depending on the
type of ADO Recordset created. You need to check ADO Help and create the
Recordset of the type that gives true count rather than -1.

--
HTH
Van T. Dinh

"Stefan" <st****@dragolov.com> wrote in message
news:89**************************@posting.google.c om...
Okay, I'm confused. The code below produces no errors and prints -1
for the RecordCount. I run it on a local Access DB. I ran the query
in Access and it returns correctly one field with one row representing
the Count...

However the Response.Write(numAvailServers) statement prints nothing !
There must be at least one record or it wouldn't go inside the
If....What am I missing here...

'Get number of available servers
strSQLquery = "SELECT COUNT(*) As resF FROM Server "
strSQLquery = strSQLquery & "WHERE server_status=1"

set rs2 = conn.Execute(strSQLquery)
Call ErrorVBScriptReport("Exuecute:" & sqrSQLQuery)
Call ErrorADOReport("Exuecute:" & sqrSQLQuery, conn)

If rs2.EOF = false Then
numAvialServers = rs2.Fields("resF")
Response.Write(numAvailServers)
Response.Write(rs2.RecordCount)
End If

Nov 12 '05 #3
The code below never asks for the RecordCount of the recordset.
He's using the Count() function to populate a column and reading
it from that column.
--
Danny J. Lesandrini
dl*********@hotmail.com
http://datafast.cjb.net

"Van T. Dinh" <Va***********@PlseUseNewsGroup.bigpond.com> wrote ...
RecordCount Property of an ADO Recordset may gives -1 (to indicate a
non-empty Recordset) rather than the actual tuple count depending on the
type of ADO Recordset created. You need to check ADO Help and create the
Recordset of the type that gives true count rather than -1.

--
HTH
Van T. Dinh

"Stefan" <st****@dragolov.com> wrote in message
news:89**************************@posting.google.c om...
Okay, I'm confused. The code below produces no errors and prints -1
for the RecordCount. I run it on a local Access DB. I ran the query
in Access and it returns correctly one field with one row representing
the Count...

However the Response.Write(numAvailServers) statement prints nothing !
There must be at least one record or it wouldn't go inside the
If....What am I missing here...

'Get number of available servers
strSQLquery = "SELECT COUNT(*) As resF FROM Server "
strSQLquery = strSQLquery & "WHERE server_status=1"

set rs2 = conn.Execute(strSQLquery)
Call ErrorVBScriptReport("Exuecute:" & sqrSQLQuery)
Call ErrorADOReport("Exuecute:" & sqrSQLQuery, conn)

If rs2.EOF = false Then
numAvialServers = rs2.Fields("resF")
Response.Write(numAvailServers)
Response.Write(rs2.RecordCount)
End If


Nov 12 '05 #4
See second last line of the code.

--
HTH
Van T. Dinh

"Danny J. Lesandrini" <dl*********@hotmail.com> wrote in message
news:br************@ID-82595.news.uni-berlin.de...
The code below never asks for the RecordCount of the recordset.
He's using the Count() function to populate a column and reading
it from that column.
--
Danny J. Lesandrini
dl*********@hotmail.com
http://datafast.cjb.net


Nov 12 '05 #5
Ooops!

And I thought I double checked before I pressed SEND.
--
Danny J. Lesandrini

"Van T. Dinh" <Va***********@discussions.microsoft.com> wrote ...
See second last line of the code.

--
HTH
Van T. Dinh


Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: thomasp | last post by:
I am trying to get a record count of a PHP query on a MS Acess database using ODBC with a DSN for MS ACCESS connection. I got this code from the PHP manual user notes. It seems to return the...
5
by: Cro | last post by:
Hello Access Developers, I'd like to know if it is possible to perform a count in an expression that defines a control source. My report is based on a query. In my report, I want a text box to...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
2
by: Volkan | last post by:
Hi, I'm trying to compare two XML documents and i'm using XPath queries to select nodes. XPathNavigator's Select method runs fast enough and returns an XPathNodeIterator object. When i try to...
1
by: heckstein | last post by:
I am working in Access 2002 and trying to create a report from our company's learming management system. I am not a DBA and most of my SQL knowledge has been self taught through trial and error. I...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
10
by: Phil Stanton | last post by:
I am trying to count the fields in a queryDef in an external database. If I run this in the actaal database I get Fields.count = 6 correctly Private Sub ObjectName_DblClick(Cancel As Integer) ...
7
by: CampbellJD1 | last post by:
I am using Access 2003 Professional. I have been working with Access for some time and I have created an MDB with a Linked Table and the Data there is temporarily transferred to other Table for...
3
by: wildThought | last post by:
If I have an object that contains a generic dictionary inside of it, how do I get access to its properties such as count?
13
by: craigchalmers | last post by:
Hi I am a complete novice so hope someone can shed some light on my problem/goal. I have an access database with some records in it. i have two fields 1) ArrivalDate 2) ReturnDate
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.