A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

sub total screen by screen



 
 
Thread Tools Display Modes
  #1  
Old September 2nd, 2006, 04:08 PM posted to microsoft.public.access.forms
Alan
external usenet poster
 
Posts: 2
Default sub total screen by screen

does anyone know how - using a tabular form - i can display sub totals at the
bottom of a screen - eg after 20 records. then have the user press a button
to display the next 20. the records are not grouped and the user does not
want a main and subform.
any thoughts would be most appreciated
--
Alan
  #2  
Old September 2nd, 2006, 08:16 PM posted to microsoft.public.access.forms
John Nurick
external usenet poster
 
Posts: 492
Default sub total screen by screen

Hi Alan,

One approach is to base the form on a query that includes a calculated
field that returns a "group number" value that increments every 20
records, and uses a parameter to control which batch of 20 records is
returned. Here's an example that works with the Orders table in the
Northwind sample database:

SELECT
A.OrderID,
A.CustomerID,
(SELECT
COUNT(B.OrderID)
FROM Orders AS B
WHERE B.OrderID = A.OrderID) AS Seq,
(SELECT
COUNT(B.OrderID) \ 20 + 1
FROM Orders AS B
WHERE B.OrderID A.OrderID) AS Grp

FROM Orders AS A

WHERE (SELECT
COUNT(B.OrderID) \ 20 + 1
FROM Orders AS B
WHERE B.OrderID A.OrderID) = [Group Number?]

ORDER BY A.OrderID;

In this example, the subquery in the WHERE clause does the hard work.
The calculated fields [Seq] and [Grp] are just there to show that it
really works (Seq numbers the records from 1 onwards, and Grp generates
the group number). In real life you'd use the actual primary key of your
table in place of OrderID, and probably replace the [Group Number?]
parameter with one that uses the Forms!FormName!ControlName syntax to
get the value from a hidden textbox on your form.

To make the whole thing work, the form would have navigation buttons
that increment or decrement value in the "group number" textbox and then
requery the form. Since the form's recordset would consist of just the
20 records being displayed, you could get the totals in the usual way by
using DSUM() expressions in unbound textboxes in the form's footer.

One drawback of this approach is that the query is not updateable. If
you want to be able to edit the records you'll need to use another
method altogether.


On Sat, 2 Sep 2006 08:08:01 -0700, Alan wrote:

does anyone know how - using a tabular form - i can display sub totals at the
bottom of a screen - eg after 20 records. then have the user press a button
to display the next 20. the records are not grouped and the user does not
want a main and subform.
any thoughts would be most appreciated


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
  #3  
Old September 3rd, 2006, 03:08 PM posted to microsoft.public.access.forms
Alan
external usenet poster
 
Posts: 2
Default sub total screen by screen

john, you're a genius! many thanks
alan
--
Alan


"John Nurick" wrote:

Hi Alan,

One approach is to base the form on a query that includes a calculated
field that returns a "group number" value that increments every 20
records, and uses a parameter to control which batch of 20 records is
returned. Here's an example that works with the Orders table in the
Northwind sample database:

SELECT
A.OrderID,
A.CustomerID,
(SELECT
COUNT(B.OrderID)
FROM Orders AS B
WHERE B.OrderID = A.OrderID) AS Seq,
(SELECT
COUNT(B.OrderID) \ 20 + 1
FROM Orders AS B
WHERE B.OrderID A.OrderID) AS Grp

FROM Orders AS A

WHERE (SELECT
COUNT(B.OrderID) \ 20 + 1
FROM Orders AS B
WHERE B.OrderID A.OrderID) = [Group Number?]

ORDER BY A.OrderID;

In this example, the subquery in the WHERE clause does the hard work.
The calculated fields [Seq] and [Grp] are just there to show that it
really works (Seq numbers the records from 1 onwards, and Grp generates
the group number). In real life you'd use the actual primary key of your
table in place of OrderID, and probably replace the [Group Number?]
parameter with one that uses the Forms!FormName!ControlName syntax to
get the value from a hidden textbox on your form.

To make the whole thing work, the form would have navigation buttons
that increment or decrement value in the "group number" textbox and then
requery the form. Since the form's recordset would consist of just the
20 records being displayed, you could get the totals in the usual way by
using DSUM() expressions in unbound textboxes in the form's footer.

One drawback of this approach is that the query is not updateable. If
you want to be able to edit the records you'll need to use another
method altogether.


On Sat, 2 Sep 2006 08:08:01 -0700, Alan wrote:

does anyone know how - using a tabular form - i can display sub totals at the
bottom of a screen - eg after 20 records. then have the user press a button
to display the next 20. the records are not grouped and the user does not
want a main and subform.
any thoughts would be most appreciated


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:46 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.