473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Count column in subform?

blyxx86
256 100+
Hey guys, I know it's possible, but I do not know how to do this...

I am looking for a way to count the total number of rows returned in a subform or a query. Similar to the way an Excel spreadsheet has the row numbers, but always starting from 1. I just hate having to physically count the items when someone wants to know how many things were finished or shipped or whatever else.

So, It looks sorta like:
ID Date Cust
005 11/4 Joe
007 11/4 Dave
010 11/5 Joe

I want those values to retun with another field in the front:
Count ID Date Cust
1 005 11/4 Joe
2 007 11/4 Dave
3 010 11/5 Joe

I would like this to be displayed within a subform, but most likely just a query. I tried using an autonumber, but it keeps 'remembering' the last value even if all the data was deleted.
Dec 12 '06 #1
9 3617
NeoPa
32,556 Expert Mod 16PB
Hey guys, I know it's possible, but I do not know how to do this...

I am looking for a way to count the total number of rows returned in a subform or a query. Similar to the way an Excel spreadsheet has the row numbers, but always starting from 1. I just hate having to physically count the items when someone wants to know how many things were finished or shipped or whatever else.

So, It looks sorta like:
ID Date Cust
005 11/4 Joe
007 11/4 Dave
010 11/5 Joe

I want those values to retun with another field in the front:
Count ID Date Cust
1 005 11/4 Joe
2 007 11/4 Dave
3 010 11/5 Joe

I would like this to be displayed within a subform, but most likely just a query. I tried using an autonumber, but it keeps 'remembering' the last value even if all the data was deleted.
I'm glad you know it can be done Blyxx86 because I don't ;).
The only way that I know of to handle this at all (and that in a complicated and unreliable manner) is to provide a Public function which can be called one way to reset the count and another way to increment and return that value.
The code, in a standard (non object) module would be something like :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function RowCount(Optional blnReset As Boolean = False) As Long
  5.     Static lngCount As Long
  6.  
  7.     If blnReset Then
  8.         lngCount = 0
  9.     Else
  10.         lngCount = lngCount + 1
  11.     End If
  12.     RowCount = lngCount
  13. End Function
You should call it from code with the blnReset option before expecting it to work correctly in your query.
Expand|Select|Wrap|Line Numbers
  1. Call RowCount(blnReset:=True)
Dec 12 '06 #2
blyxx86
256 100+
I'm glad you know it can be done Blyxx86 because I don't ;).
The only way that I know of to handle this at all (and that in a complicated and unreliable manner) is to provide a Public function which can be called one way to reset the count and another way to increment and return that value.
The code, in a standard (non object) module would be something like :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function RowCount(Optional blnReset As Boolean = False) As Long
  5.     Static lngCount As Long
  6.  
  7.     If blnReset Then
  8.         lngCount = 0
  9.     Else
  10.         lngCount = lngCount + 1
  11.     End If
  12.     RowCount = lngCount
  13. End Function
You should call it from code with the blnReset option before expecting it to work correctly in your query.
Expand|Select|Wrap|Line Numbers
  1. Call RowCount(blnReset:=True)
Well, actually... Does it really need to be a public function? I have a seperate table that information is output to when I run a specific query, so I could just have it reset the boolean row count of a certain autonumber column?

Or is there any way to have a function similar to an excel function in a column?
Then I could just do a =SUM(A1:A1)+1 type of thing (I can't think of what the actual excel function would be, much too tired to think.)
Dec 12 '06 #3
NeoPa
32,556 Expert Mod 16PB
That fundamentally wouldn't work.
If it did you wouldn't even really need to ask the question.
You're welcome to see if you can work out a way.
Don't forget to post the solution here if you find or develop one though ;).
Dec 12 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
Hey guys, I know it's possible, but I do not know how to do this...

I am looking for a way to count the total number of rows returned in a subform or a query. Similar to the way an Excel spreadsheet has the row numbers, but always starting from 1. I just hate having to physically count the items when someone wants to know how many things were finished or shipped or whatever else.

So, It looks sorta like:
ID Date Cust
005 11/4 Joe
007 11/4 Dave
010 11/5 Joe

I want those values to retun with another field in the front:
Count ID Date Cust
1 005 11/4 Joe
2 007 11/4 Dave
3 010 11/5 Joe

I would like this to be displayed within a subform, but most likely just a query. I tried using an autonumber, but it keeps 'remembering' the last value even if all the data was deleted.
In the form footer of the subform put an unbound textbox (txtRecCount) and a command button (cmdGetRecCount). In the code for cmdGetRecCount put the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdGetRecCount_Click()
  2.  
  3.    Me.txtRecCount = Me.RecorsetClone.RecordCount
  4.  
  5. End Sub
  6.  
Mary
Dec 13 '06 #5
NeoPa
32,556 Expert Mod 16PB
In the form footer of the subform put an unbound textbox (txtRecCount) and a command button (cmdGetRecCount). In the code for cmdGetRecCount put the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdGetRecCount_Click()
  2.  
  3.    Me.txtRecCount = Me.RecorsetClone.RecordCount
  4.  
  5. End Sub
  6.  
Mary
Mary,

Shock Horror!
He's after the ordinal for each record in the dataset!
Dec 13 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
Mary,

Shock Horror!
He's after the ordinal for each record in the dataset!
Original question only asked for a count.

Mary
Dec 13 '06 #7
NeoPa
32,556 Expert Mod 16PB
Shock Horror referred to our shared understanding of why that's not a reasonable expectation. I wasn't being derisory (wouldn't dare).
Original question only asked for a count.

Mary
Although the original post used that term it was just miscommunication from his example output.
Dec 13 '06 #8
blyxx86
256 100+
Shock Horror referred to our shared understanding of why that's not a reasonable expectation. I wasn't being derisory (wouldn't dare).

Although the original post used that term it was just miscommunication from his example output.
But actually... the solution would work. I do not necesarily need a new column if I can get something that would just output the number of records (which is what I'm going after anyways.)

Although I can see a use for resetting the count of an autonumber column, in my current situation, just counting total records would be perfect.

I'm guessing I can post that code and make the value of a textbox display the number.

Again, thank you both - I have no idea what this "Shock Horror" is, but it sounds much like The Rocky Horror Picture Show
Dec 13 '06 #9
NeoPa
32,556 Expert Mod 16PB
Ahh. The problem changes again :(.
In that case a simple record count will do you (and is infinitely easier).
Rocky Horror Picture Show is a favourite classic film of mine.
Shock Horror, in this case though, refers to the earlier request for something which is a no-no in an RDBMS (This was directed at Mary and she would understand :) ).
Dec 14 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: A Clark | last post by:
I have a subform that displays a datasheet. There are a couple of different queries that can be displayed in the datasheet. The queries are available in a combo box on the main form. The problem...
1
by: angel duran | last post by:
Hi... i'm trying to accomplish this and i will be using some pictures so you can easily follow me along. I have this form <link>http://img30.exs.cx/my.php?loc=img30&image=4214.jpg</link> and in...
1
by: Thomas Zimmermann | last post by:
I have a form with a subform in datasheet view. Now, I want to trigger a procedure (P1) each time the user selects an entire column (by clicking in the heading) in the subform. The procedure (P1) I...
1
by: Kev | last post by:
Hi, I am trying to total a column (Shift1) in a subform (continous forms) from the after update event of the (Shift1) column control within the subform. This column stores shift codes, I want to...
1
by: christianlott1 | last post by:
I want to provide users with an interface to create a custom merge (all in Access, not Word). User will put in a set of brackets ("<>") in a memo field and when they click the merge button it will...
7
by: ncsthbell | last post by:
I have a form which includes a subform. I have modified the design of the subform to include a new column called 'Diff'. When I open up the form and the subform is loaded, the new column I added is...
2
by: ncsthbell | last post by:
I have a form with a subform and I am trying to change the size of a column on the subform. I am following the instructions in the access help 'Change the layout of a subform in Datasheet view" to...
1
by: ncsthbell | last post by:
Here is the scenario. I have a form-"formA", I created another form-"FormB" which will be placed on FormA . I go to FormA in desgn view and use the button for "create subform" to bring in "FormB"...
2
by: DeanL | last post by:
Hi everyone, I have a subform in datasheet view that is used to display the contents of a single table. I have another subform with a query feeding it to give a count of how many particular...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.