Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: RE: pro_vb digest: August 23, 2001


Message #1 by "Punshon, Keith" <Keith.Punshon@t...> on Fri, 24 Aug 2001 09:38:40 +0100
	You need to read the Recordset after applying the SQL statement
	Try this

	Public Function GetRecordCount() As Long
	Dim strSQl As String
	    	Dim db As DAO.Database
	    	Dim rs As DAO.Recordset
	    
	    	strSQl = "SELECT COUNT(*) AS THISISRECORDCOUNT FROM
TABLENAMEHERE"
	    
	    	Set db = OpenDatabase(DatabaseName)
	    	Set rs = db.OpenRecordset(strSQl, dbOpenDynaset)
	GetRecordCount = rs.Fields("THISISRECORDCOUNT")
	    
	    	Set rs = Nothing
	    	Set db = Nothing

	End Function

	This is using DAO, but you can do the same in ADO



	>From: "N J" <goodsubbie@h...>
	>Reply-To: "professional vb" <pro_vb@p...>
	>To: "professional vb" <pro_vb@p...>
	>Subject: [pro_vb] AS/400 Application SQL Question
	>Date: Wed, 22 Aug 2001 16:30:54 -0400
	>
	>Hi,
	>    I am currently writing a program that is accessing an as400
system.  I
	>am running SQL statement against the 400 to get the results into a
	>recordset.  I want to be able to get the count of the recordsets.
I have
	>tried rs.recordcount but that fails to return an actual number
because the
	>database is not static so therefore it will only return a -1 or a
0.  I 
	>know
	>with SQL you can setup a statement to get a count of records like
	>strsql = "SELECT COUNT(*) FROM TABLENAMEHERE"
	>now the only problem is returning the count in to a variable I am
not sure
	>how this can be done or if it even can be done.  I have tried
declaring it
	>as an alias such as
	>
	>strsql = "SELECT COUNT(*) AS THISISRECORDCOUNT FROM TABLENAMEHERE"
	>msgbox THISISRECORDCOUNT
	>
	>even tho that was a long shot giving it an alias i tried it. Any
help will
	>be greatly appreciated.
	>
	>Thanks in advance,  

  Return to Index