Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with totals please 1

Status
Not open for further replies.

timdodgson

Technical User
Jun 12, 2000
111
GB
I am very new to asp and also quite new to access so please alittle help. My problem i havw access database that i have made an asp from by using dreamweaver you could vist this page at the page works by pulling simple data from an access database "hourly rate" "Hours Visited" "Date" "Spares" and "Spares cost" come fom a query "Total"is made by hourly rate * Hours visited + spares cost this all works ok but what i want is a grand total at the bottom ie under totals colume
any help please and thanks in advance
Tim Dodgson
Tim Dodgson
timdodgson@yahoo.co.uk
 
As you are looping through the recordset, you could add the amount to a variable and display the variable at the end.

Do While Not rs.EOF
...print your table row...
total1=total1+rs.Fields("column1")
total2=total2+rs.Fields("column2")
total3=total3+rs.Fields("column3")
rs.MoveNext
Loop
...Print out total variables here... Adam
 
Sounds like a good reply Thank You bit i am not sure how to insert it into my page the column i am trying to total is called totals any more help PLEEEEEASa
many Thanks in Advance
Tim Dodgson
Tim Dodgson
timdodgson@yahoo.co.uk
 
OK... if you are only wanting the total of the totals column, inside of your loop, you will need to set a variable (grandtotal) equal to your total formula + the old grandtotal:

total = hourly rate * Hours visited + spares cost
grandtotal = grandtotal + total

after you get done looping through the records, you can the write out the grandtotal variable to the screen:

response.write "Grand Total: " & grandtotal

If you still don't understand, post your code and I will try to walk you through it using your code...

mwa
 
Thank You so much for your help but i just have not got the knolage to hang code this so as you sujested iwill post my code

CODE
<%@LANGUAGE=&quot;VBSCRIPT&quot; CODEPAGE=&quot;1252&quot;%>
<!--#include file=&quot;Connections/Customer.asp&quot; -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Recordset1.ActiveConnection = MM_Customer_STRING
Recordset1.Source = &quot;SELECT * FROM [Greenbank School]&quot;
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

Dim Recordset1_total
Dim Recordset1_first
Dim Recordset1_last

' set the record count
Recordset1_total = Recordset1.RecordCount

' set the number of rows displayed on this page
If (Recordset1_numRows < 0) Then
Recordset1_numRows = Recordset1_total
Elseif (Recordset1_numRows = 0) Then
Recordset1_numRows = 1
End If

' set the first and last displayed record
Recordset1_first = 1
Recordset1_last = Recordset1_first + Recordset1_numRows - 1

' if we have the correct record count, check the other stats
If (Recordset1_total <> -1) Then
If (Recordset1_first > Recordset1_total) Then
Recordset1_first = Recordset1_total
End If
If (Recordset1_last > Recordset1_total) Then
Recordset1_last = Recordset1_total
End If
If (Recordset1_numRows > Recordset1_total) Then
Recordset1_numRows = Recordset1_total
End If
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them

If (Recordset1_total = -1) Then

' count the total records by iterating through the recordset
Recordset1_total=0
While (Not Recordset1.EOF)
Recordset1_total = Recordset1_total + 1
Recordset1.MoveNext
Wend

' reset the cursor to the beginning
If (Recordset1.CursorType > 0) Then
Recordset1.MoveFirst
Else
Recordset1.Requery
End If

' set the number of rows displayed on this page
If (Recordset1_numRows < 0 Or Recordset1_numRows > Recordset1_total) Then
Recordset1_numRows = Recordset1_total
End If

' set the first and last displayed record
Recordset1_first = 1
Recordset1_last = Recordset1_first + Recordset1_numRows - 1

If (Recordset1_first > Recordset1_total) Then
Recordset1_first = Recordset1_total
End If
If (Recordset1_last > Recordset1_total) Then
Recordset1_last = Recordset1_total
End If

End If
%>
<html>
<head>
<title>Greenbank Invoice</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName==&quot;Netscape&quot;)&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>

<body>
<div id=&quot;Layer1&quot; style=&quot;position:absolute; left:0px; top:0px; width:550px; height:420px; z-index:1&quot;></div>
<div id=&quot;Layer2&quot; style=&quot;position:absolute; left:448px; top:6px; width:72px; height:96px; z-index:2&quot;><img src=&quot;CAIVUZSL.jpg&quot; width=&quot;102&quot; height=&quot;104&quot;></div>
<div id=&quot;Layer3&quot; style=&quot;position:absolute; left:10px; top:6px; width:345px; height:40px; z-index:3&quot;><font color=&quot;#006699&quot; size=&quot;6&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Business
Integr@tion </font></div>
<div id=&quot;Layer4&quot; style=&quot;position:absolute; left:10px; top:41px; width:347px; height:118px; z-index:4&quot;>
<p><font color=&quot;#000000&quot; size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>163 Old
Chapel St,<br>
Edgeley,</font><font size=&quot;2&quot;><br>
<font face=&quot;Arial, Helvetica, sans-serif&quot;>Stockport,<br>
Cheshire,<br>
SK3 9JL<br>
<strong>T</strong>el: 0161 474 7968 <strong>F</strong>ax: 0161 474 0206<br>
<strong>E</strong>mail <a href=&quot;mailto:greenbankinvoice@businessintegration.biz&quot;>greenbankinvoice@businessintegration.biz</a></font></font>
<br>
</p>
</div>
<div id=&quot;Layer5&quot; style=&quot;position:absolute; left:10px; top:169px; width:407px; height:23px; z-index:5&quot;><font color=&quot;#006699&quot; size=&quot;6&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Invoice
to Greenbank School</font></div>
<div id=&quot;Layer6&quot; style=&quot;position:absolute; left:10px; top:203px; width:539px; height:6px; z-index:6&quot;>
<hr>
</div>

<div id=&quot;Layer7&quot; style=&quot;position:absolute; left:10px; top:229px; width:540px; height:70px; z-index:7&quot;>
<table width=&quot;540&quot; border=&quot;0&quot; bordercolor=&quot;#FFFFFF&quot;>
<tr>
<td width=&quot;90&quot;><div align=&quot;center&quot;><font color=&quot;#006699&quot; size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Hourly
Rate</font></div></td>
<td width=&quot;90&quot;><div align=&quot;center&quot;><font color=&quot;#006699&quot; size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Hours
Visited</font></div></td>
<td width=&quot;90&quot;><div align=&quot;center&quot;><font color=&quot;#006699&quot; size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Date</font></div></td>
<td width=&quot;90&quot;><div align=&quot;center&quot;><font color=&quot;#006699&quot; size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Spares</font></div></td>
<td width=&quot;90&quot;><div align=&quot;center&quot;><font color=&quot;#006699&quot; size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Spares
Cost</font></div></td>
<td width=&quot;90&quot;><div align=&quot;center&quot;><font color=&quot;#006699&quot; size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Total</font></div></td>
</tr>
<% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) %>
<tr>
<td><div align=&quot;center&quot;>&pound;<%=(Recordset1.Fields.Item(&quot;Hourly Rate&quot;).Value)%></div></td>
<td><div align=&quot;center&quot;><%=(Recordset1.Fields.Item(&quot;Hours Visted&quot;).Value)%></div></td>
<td><div align=&quot;center&quot;><font size=&quot;2&quot;><%=(Recordset1.Fields.Item(&quot;Date&quot;).Value)%></font></div></td>
<td><div align=&quot;center&quot;><font size=&quot;2&quot;><%=(Recordset1.Fields.Item(&quot;Spares&quot;).Value)%></font></div></td>
<td><div align=&quot;center&quot;>&pound;<%=(Recordset1.Fields.Item(&quot;Spares Cost&quot;).Value)%></div></td>
<td><div align=&quot;center&quot;>&pound;<font size=&quot;3&quot;><%=(Recordset1.Fields.Item(&quot;Totals&quot;).Value)%></font></div></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</table>
THIS IS WHERE I WOULD LIKE THE GRAND TOTAL
<br>
<hr>
</div>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
CODE
Again Many Thanks
Tim Dodgson
Tim Dodgson
timdodgson@yahoo.co.uk
 
[red]try replacing this:[/red]

Code:
<% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) %>
    <tr> 
      <td><div align=&quot;center&quot;>£<%=(Recordset1.Fields.Item(&quot;Hourly Rate&quot;).Value)%></div></td>
      <td><div align=&quot;center&quot;><%=(Recordset1.Fields.Item(&quot;Hours Visted&quot;).Value)%></div></td>
      <td><div align=&quot;center&quot;><font size=&quot;2&quot;><%=(Recordset1.Fields.Item(&quot;Date&quot;).Value)%></font></div></td>
      <td><div align=&quot;center&quot;><font size=&quot;2&quot;><%=(Recordset1.Fields.Item(&quot;Spares&quot;).Value)%></font></div></td>
      <td><div align=&quot;center&quot;>£<%=(Recordset1.Fields.Item(&quot;Spares Cost&quot;).Value)%></div></td>
      <td><div align=&quot;center&quot;>£<font size=&quot;3&quot;><%=(Recordset1.Fields.Item(&quot;Totals&quot;).Value)%></font></div></td>
    </tr>
    <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
  </table>
  THIS IS WHERE I WOULD LIKE THE GRAND TOTAL

[red]with this:[/red]

Code:
<% DIM curGrandTotal
    curGrandTotal = 0
    While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) %>
    <tr> 
      <td><div align=&quot;center&quot;>£<%=(Recordset1.Fields.Item(&quot;Hourly Rate&quot;).Value)%></div></td>
      <td><div align=&quot;center&quot;><%=(Recordset1.Fields.Item(&quot;Hours Visted&quot;).Value)%></div></td>
      <td><div align=&quot;center&quot;><font size=&quot;2&quot;><%=(Recordset1.Fields.Item(&quot;Date&quot;).Value)%></font></div></td>
      <td><div align=&quot;center&quot;><font size=&quot;2&quot;><%=(Recordset1.Fields.Item(&quot;Spares&quot;).Value)%></font></div></td>
      <td><div align=&quot;center&quot;>£<%=(Recordset1.Fields.Item(&quot;Spares Cost&quot;).Value)%></div></td>
      <td><div align=&quot;center&quot;>£<font size=&quot;3&quot;><%=(Recordset1.Fields.Item(&quot;Totals&quot;).Value)%></font></div></td>
    </tr>
    <% 
  curGrandTotal = curGrandTotal + Recordset1.Fields.Item(&quot;Totals&quot;).Value
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
  </table>
  <%'THIS IS WHERE I WOULD LIKE THE GRAND TOTAL%>
  <B>Grand Total: <%=formatcurrency(curGrandTotal)%><B>

[red]Try that and let me know how it goes...

mwa[/red]
 
Thank You so much
It worked OK i have been on a very steep learning curve (everest) i had actuly nearly done it brackets and dots doing my head in

Again thank youvery much
If i can help you i have mcse nvq4 sage certified
just give us a shoot
timdodgson@yahoo.co.uk

Timdodgson
Tim Dodgson
timdodgson@yahoo.co.uk
 
sorry meant to say the formatcurencey command came up as dollers even though i have pounds set in control panel i just changed code to £ sign just wondered if you have any ideas
Tim Dodgson
timdodgson@yahoo.co.uk
 
Sorry about that... just habit on the formatcurrency... I'm not sure how to put £ in there... I'm glad the other worked for you...

I'll keep you in mind if I ever cross a path where I need something...

mwa

P.S....

Not that I'm asking for this, but for future reference... If someone helps you out, you can show everyone else by giving that person a star... Just click the link that says &quot;Mark this post as a helpful/expert post!&quot;... Later...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top