Link to home
Create AccountLog in
Avatar of bogorman
bogorman

asked on

Calculating two totals from a recordset

I am using CodeCharge Studio to develop a website.
In the BeforeShow event of a webpage, I want to count:
1. the number of records which have a particular field which has data in it
2. the number of records where this field has no data in it.
I have used this coding which displays -1 for the first.

Dim SQLEmails, SQLNoEmails, TotalEmails, TotalNoEmails, UserID, Connection
Dim myConn, myCmd, myRS

Set Connection = New clsDBConnection1
Connection.Open

UserID = Connection.ToSQL(CCGetUserID(), ccsInteger)

Connection.Close
Set Connection = Nothing
On Error Goto 0


Set myConn = Server.CreateObject("ADODB.Connection")
Set myCmd = Server.CreateObject("ADODB.Command")
Set myRS = Server.CreateObject("ADODB.Recordset")

myConn.Open("dsn=lifenet;uid=brianog;password=boggle")


SQLEmails = "SELECT COUNT(*) FROM tblselectedschools WHERE fldUserID = " & UserID & " AND TRIM(tblselectedschools.fldEmail) <> ''"
SQLNoEmails = "SELECT COUNT(*) FROM tblselectedschools WHERE fldUserID = " & UserID & " AND TRIM(tblselectedschools.fldEmail) = ''"


With myCmd
.ActiveConnection = myConn

.CommandText = SQLEmails ' This should be your SQL select statement
.CommandType = 1 'adCmdText
End With

myRS.Open myCmd
TotalEmails=myRS.RecordCount


response.Write TotalEmails
response.end

MyConn.Close
Header.lblHeaderLeft.Value="School email addresses"

I am sure there is an easier way of doing this. Would be grateful for anyone's help.



ASKER CERTIFIED SOLUTION
Avatar of Member_2_3718378
Member_2_3718378

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of bogorman
bogorman

ASKER

Hi,
Thanks so much for your help.
Could not get deathtospam's SQL to work, but pasted jman's in its place and the combined code is excellent.
Thank you both again. Have divided the points.
Brian
Glad we could help.