G
Guest
I have an Access database used to track donor pledges. In it, there is a
table that contains three fields for each donor: Gift_Amount, Gift_Per_Year,
and Matching_Gift_Ratio.
The following formula would calculate the total pledge amount for each
donor:
(Gift_Amount * Gift_Per_Year) * (Matching_Gift_Ratio + 1).
A total Pledge for all donors would just sum up the calculated values.
My goal is to create an ASP that would show this total amount pledged. Here
is the ASP that I have created so far:
***********************************************
<html>
<head>
<title>Pledge Totals</title>
</head>
<body bgcolor="white" text="black">
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsGiving 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database
Dim totalamt 'Holds the Total Pledge amount, a calculated field
Dim dollars 'Holds the formated currency amount
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less
connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("Careathon_SP2004.mdb")
'Set an active connection to the Connection object using DSN connection
'adoCon.Open "Careathon_SP2004"
'Create an ADO recordset object
Set rsGiving = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT Giving.Gift_Amount, Giving.Gifts_Per_Year,
Giving.Matching_Gift_Ratio FROM Giving WHERE Gift_Amount>0 AND
Gifts_Per_Year>0"
'Open the recordset with the SQL query
rsGiving.Open strSQL, adoCon
'Loop through the recordset
Do While not rsGiving.EOF
'Calculate total donor pledge and add to cumulative total - THIS IS WHERE
THE CODE STOPS AND THE ERROR OCCURS
totalamt = totalamt + ((rsGiving("Gift_Amount") *
rsGiving("Gifts_Per_Year")) * (rsGiving("Matching_Gift_Ratio") + 1))
'Move to the next record in the recordset
rsGiving.MoveNext
Loop
'Formats the total amount to currency
'set dollars = FormatCurrency(totalamt, 2, -1, 0, 1)
'Write the HTML to display the total pledge amount
Response.Write ("<br> $ ")
'Response.Write (dollars)
Response.Write (totalamt)
Response.Write ("<br>")
'Reset server objects
rsGiving.Close
Set rsGiving = Nothing
Set adoCon = Nothing
Set totalamt = Nothing
Set dollars = Nothing
%>
</body>
</html>
**********************************************
However, when I run this page, I get the following error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
It occurs on the line with the calculations.
What do I need to change in order for this page to work correctly?
table that contains three fields for each donor: Gift_Amount, Gift_Per_Year,
and Matching_Gift_Ratio.
The following formula would calculate the total pledge amount for each
donor:
(Gift_Amount * Gift_Per_Year) * (Matching_Gift_Ratio + 1).
A total Pledge for all donors would just sum up the calculated values.
My goal is to create an ASP that would show this total amount pledged. Here
is the ASP that I have created so far:
***********************************************
<html>
<head>
<title>Pledge Totals</title>
</head>
<body bgcolor="white" text="black">
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsGiving 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database
Dim totalamt 'Holds the Total Pledge amount, a calculated field
Dim dollars 'Holds the formated currency amount
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less
connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("Careathon_SP2004.mdb")
'Set an active connection to the Connection object using DSN connection
'adoCon.Open "Careathon_SP2004"
'Create an ADO recordset object
Set rsGiving = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT Giving.Gift_Amount, Giving.Gifts_Per_Year,
Giving.Matching_Gift_Ratio FROM Giving WHERE Gift_Amount>0 AND
Gifts_Per_Year>0"
'Open the recordset with the SQL query
rsGiving.Open strSQL, adoCon
'Loop through the recordset
Do While not rsGiving.EOF
'Calculate total donor pledge and add to cumulative total - THIS IS WHERE
THE CODE STOPS AND THE ERROR OCCURS
totalamt = totalamt + ((rsGiving("Gift_Amount") *
rsGiving("Gifts_Per_Year")) * (rsGiving("Matching_Gift_Ratio") + 1))
'Move to the next record in the recordset
rsGiving.MoveNext
Loop
'Formats the total amount to currency
'set dollars = FormatCurrency(totalamt, 2, -1, 0, 1)
'Write the HTML to display the total pledge amount
Response.Write ("<br> $ ")
'Response.Write (dollars)
Response.Write (totalamt)
Response.Write ("<br>")
'Reset server objects
rsGiving.Close
Set rsGiving = Nothing
Set adoCon = Nothing
Set totalamt = Nothing
Set dollars = Nothing
%>
</body>
</html>
**********************************************
However, when I run this page, I get the following error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
It occurs on the line with the calculations.
What do I need to change in order for this page to work correctly?