Create sequence number for table

Hi,
I have a table with a Title field, comment field and a Sequence field.  I 
would like code to sort the table by Title and then fill in the Sequence 
field based on the order of the records.  The first record would have a 
sequence number of 1, the second record a 2, etc.  
Can someone help me with code to do this?
Thanks in advance.
  
0
Utf
3/27/2010 2:55:01 AM
access 16762 articles. 3 followers. Follow

6 Replies
4765 Views

Similar Articles

[PageSpeed] 43

"Phillip" <Phillip@discussions.microsoft.com> wrote in message 
news:432342F6-AD55-405B-8CDF-43414FBE421D@microsoft.com...
> Hi,
> I have a table with a Title field, comment field and a Sequence field.  I
> would like code to sort the table by Title and then fill in the Sequence
> field based on the order of the records.  The first record would have a
> sequence number of 1, the second record a 2, etc.
> Can someone help me with code to do this?
> Thanks in advance.

The question is _why_ would you want to do this? You can sort the table by 
Title whenever you want to use it. And, with what you are asking for, what 
happens when you add a record that sorts between two existing titles?

Records in a relational table are, by definition, UNordered.  The relational 
way is that you order the records in the Query you use to retrieve them, 
preferrably by some included natural value.

It would be possible to do what you want, but then all you could do with 
that is to use it to order the records which you can already do, as you 
stated, by sorting by title.

 Larry Linson
 Microsoft Office Access MVP 



0
Larry
3/27/2010 3:10:03 AM
On Fri, 26 Mar 2010 19:55:01 -0700, Phillip
<Phillip@discussions.microsoft.com> wrote:

>Hi,
>I have a table with a Title field, comment field and a Sequence field.  I 
>would like code to sort the table by Title and then fill in the Sequence 
>field based on the order of the records.  The first record would have a 
>sequence number of 1, the second record a 2, etc.  
>Can someone help me with code to do this?
>Thanks in advance.
>  

It's a bad idea.

Suppose you have 3127 records and then add "Aardvark" as a new title.

Do you renumber 3125 records to make room for the new entry?

What if the sequence number is referenced in five other tables? Or 200 copies
of a printout? Or in a dozen people's memories? Do you erase them all to make
the change?

If you recognize that it's a bad idea, or you have good reason to believe that
your database is an exception, you can run an Update query. Create a query
based on the table, and update Sequence to

=DCount("*", "yourtable", "[Title] <= " & [Title])

This will count all the records with a title up to and including the current
record's title, and plunk that into the Sequence field.

Don't edit or add any titles after you do this, or you'll have to do it all
over again.
-- 

             John W. Vinson [MVP]
0
John
3/27/2010 3:11:03 AM
FYI
I want to do this to print a report with one record per page and with page 
numbers.
I can then also produce a table of contents from the table using the 
sequence number as page numbers.  Then I can also produce the 5 index tables 
I need based on the other fields in the table.  The index tables are very 
easy to produce if the page numbers are in the table.  Each time I want to 
produce the report the sequence numbers would be updated for new or deleted 
records and I can procude the table contents and index tables with the touch 
of a button.
If there is a better way to do this I don't know how.........
"John W. Vinson" wrote:

> On Fri, 26 Mar 2010 19:55:01 -0700, Phillip
> <Phillip@discussions.microsoft.com> wrote:
> 
> >Hi,
> >I have a table with a Title field, comment field and a Sequence field.  I 
> >would like code to sort the table by Title and then fill in the Sequence 
> >field based on the order of the records.  The first record would have a 
> >sequence number of 1, the second record a 2, etc.  
> >Can someone help me with code to do this?
> >Thanks in advance.
> >  
> 
> It's a bad idea.
> 
> Suppose you have 3127 records and then add "Aardvark" as a new title.
> 
> Do you renumber 3125 records to make room for the new entry?
> 
> What if the sequence number is referenced in five other tables? Or 200 copies
> of a printout? Or in a dozen people's memories? Do you erase them all to make
> the change?
> 
> If you recognize that it's a bad idea, or you have good reason to believe that
> your database is an exception, you can run an Update query. Create a query
> based on the table, and update Sequence to
> 
> =DCount("*", "yourtable", "[Title] <= " & [Title])
> 
> This will count all the records with a title up to and including the current
> record's title, and plunk that into the Sequence field.
> 
> Don't edit or add any titles after you do this, or you'll have to do it all
> over again.
> -- 
> 
>              John W. Vinson [MVP]
> .
> 
0
Utf
3/27/2010 4:19:01 AM
On Fri, 26 Mar 2010 21:19:01 -0700, Phillip
<Phillip@discussions.microsoft.com> wrote:

>If there is a better way to do this I don't know how.........

There is; on a Report you can put a textbox with a control source of =1, and
set its Running Sum property to Over All. The first textbox will show a 1, the
second 2, and so on ad infinitum; and it will recalculate next time you run
the report, even if the data changes.
-- 

             John W. Vinson [MVP]
0
John
3/27/2010 5:09:40 AM
Are the titles UNIQUE and is the TITLE field a text (not memo) field?  Does 
the table have a primary key?

You should be able to create a ranking column in a query to give you the 
needed number based on the title and (if needed) the primary key.  With the 
ranking number you can generate the other documents you want.

Is the comment field a memo field?  If so that makes the solution slightly 
more complex.  I will assume so.

Assuming UNIQUE titles the ranking query would look like:
SELECT A.Title, Count(B.Title) as RankNumber
FROM [YourTable] as A INNER JOIN [YourTable] as B
ON A.Title >= B.Title
GROUP BY A.Title

You could then join that to your table in another query to add in the comment 
field (assuming it is a memo field).

SELECT A.Title, A.Comment, Q.Rank
FROM [YourTable] as A INNER JOIN qRankingQuery as Q
ON A.Title = Q.Title


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Phillip wrote:
> Hi,
> I have a table with a Title field, comment field and a Sequence field.  I 
> would like code to sort the table by Title and then fill in the Sequence 
> field based on the order of the records.  The first record would have a 
> sequence number of 1, the second record a 2, etc.  
> Can someone help me with code to do this?
> Thanks in advance.
>   
0
John
3/27/2010 12:11:38 PM
On Fri, 26 Mar 2010 23:09:40 -0600, John W. Vinson
<jvinson@STOP_SPAM.WysardOfInfo.com> wrote:

>There is; on a Report you can put a textbox with a control source of =1, and
>set its Running Sum property to Over All. The first textbox will show a 1, the
>second 2, and so on ad infinitum; and it will recalculate next time you run
>the report, even if the data changes.

But then you don't have the information for the table of contents.

In this case I suggest you load a work table (or tables) with
everything you need for the report - data records, sequences, TOC
entries, etc.  I wouldn't update the sequence values in the main table
- too messy, plus it won't handle multiple users running the reports
concurrently.

Armen Stein
Microsoft Access MVP
www.JStreetTech.com
 
0
Armen
3/28/2010 6:15:33 PM
Reply:

Similar Artilces:

create a roster
How can you create a weekly roster in which functions can be assigned to more than 10 people. The roster should be updatable, so that when holidays and days off are marked on the weekly roster they will be taken account of it future rosters. ...

Irregular formation of numbers
Hi, I hope someone can help, I am trying to format numbers in a column. the numbers are all 10 digits (ie. 0405613020) and from cell to cel are all different. What I am trying to do is for them to take on the format below: 0405.61.30.20 I have tried different things.. but nothing seems to work.. I have ove 250 cells that need to look like that, and it's very long and tedious.. Hope someone can help me.. Diamonelle :confused -- Message posted from http://www.ExcelForum.com Hi You can put this formula in a helper column, copy it down as far a needed and then copy-paste special -...

So many Tunnel Adapters
Hi, I understand that Tunnel Adapter LAN is for encapsulating IPv6 packets with an IPv4 header so that they can be sent across an IPv4 network. Few queries popped up in my mind based on this :- 1. Why is the numbering for the Tunnel adapter LAN not sequential ? It is like 6,7,12,13,14,15,16. A strange numbering scheme ?! I tried to figure it out by thinking of some arithmetic series. But, it does not seem to fit in. There is a huge gap between 7 and 12. Any ideas ? 2. What is the need for so many number of Tunnel Adapter LAN connection ? Can you tell me a scenario that re...

importing or creating reference footnotes
I am trying to import a word document into publisher and it has reference footnotes within the document. The reference footnotes are not coming into the publisher document with the reference footnotes. Correct, they will not up to Publisher 2003. In Publisher 2003 depending on which version of Word you are using if they will or not. -- "If you don't know where you are going, any road will take you there!" ...

Mailbox not created when AD account created
A couple of days ago I noticed that I created a user account but the 'Email Addresses' tab of the user properies did not list any email addresses. Subsequent new user accounts have all experienced the same. I researched the knowledge and tried the recommended solutions to either manaully start the recipient update service or rebuild te recipient update service. Neither recommendation has resulted in a mailbox being created for this particular user or any additional user that I have created since this error first showed up. I performed a Windows update last Thursday and so I bel...

VBA Question
Hi, I have a form with a combobox control that list some sizes. They are: 12 18 20 22 I have another text box for keying a custom size, such as 12'2". What I would like to do is have the combobox default to the next size (in this case 18). Here's the code I have used so far (it does a little more than what I am asking for but to give an idea): Dim MCUST As String MCUST = Me.custwidth If Str(Me.widthck) <> Me.custwidth Or Len(Me.custwidth) <> Len(Me.widthck) Then Me.widthck.Value = Int(Val(MCUST)) + 1 If InStr(Int(Me.widthck) / 2, ".&...

Task Create - Status
I'm trying to make a simple task, when a user owner is assigned a task in CRM, it receives an email letting it know it has one. I have the following below, but it is not generating one when i assign one manually in the CRM. What to do? I've tried both the following: When task is created E-Mail to:[owner];Subject test As well as: When task is created if Task activity status = Open then E-Mail to:[owner];Subject test I've checked the mailserver many times over, and I can send emails manually from the CRM so you can rule that out Tested out ok on our end. Some ideas:...

Add a specific Record to a Table based on a check box
I have a Table called ServiceTypes. Based on a User's input on a ProposalForm, ServiceTypes need to be added to a ProposalServicesTable. For instance, I have a Check Box on the ProposalForm. When a Check Box is clicked Yes, Access must search the ServiceTypes Table, select a specific ServiceTypeID, and add the ServiceType to the ProposalServicesTable. How can I add the proper Service record from the ServiceTable to the ProposalServicesTable based on the Check Box? I wouldn't do it that way. I'd use a listbox (with multi-select set to YES) that was sourced to the ServiceTab...

Pivot Table update without opening the Excel file.
Hi, I have a spreadsheet saved as an xlt. It has three pivot tables which connect to CSV data files using Microsoft Text Driver. The CSV files are updated overnight by an external application. The Excel file is in \\Server\Viewers The Data files are in \\Server\Data Local users use a shortcut to open the Excel file on \\Server\Viewers which the does an auto-update from the CSV files. The pivot table data is updated. All that has been working perfectly for years, internally. Now I need to send the same excel file to another company by email. I have succeeded in writing a vbscript that creates...

Query on Group field in Pivot Table
I have a large database wherein under Date column, data is in the format "Thu Oct 1 12:00 AM". When I use Pivot Table Under OPTIONS->GROUP-> Group Field is disabled. I used this to group Date field to either present data by Month, quarter at one click. Can anybody guide me why this seems to be disabled here. I want to present my data only by Monthwithout changing the format ""Thu Oct 1 12:00 AM". Thanks Hi Shewta Check you Data Source of your Pivot. it should come up like "Sheet6!$G$1:$I$821" and not like "'\Documents and...

Need to store a customer's shipper number
We often ship orders to customers using their UPS or FedEx acocunt number and would like to be able to store the number in GP rather than ask the customer for the number and communicate it to shipping with each order. Does anyone have any ideas about where it would be best stored rather than a Ship Method? There are two User Defined fields on the Customer Maintenance Window, or you can use the "I" Internet information window for the Customer to store in the User Defined fileds in the internet information window. If you use the internet information window then you will need to use...

Distribution List Max Number of Recipients
Does anyone know what the maximum number of recipients allowed in a distribution list is in Exchange 5.5 Thanks. "L. Wagoner" <anonymous@discussions.microsoft.com> wrote: >Does anyone know what the maximum number of recipients allowed in a distribution list is in Exchange 5.5? It's somewhere in the vicinity of 5,000. -- Rich Matheisen MCSE+I, Exchange MVP MS Exchange FAQ at http://www.swinc.com/resource/exch_faq.htm ...

Bug with cell merging in tables using Applescript
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Once you have merged cells in a table in Word 2008 using Applescript, any further reference to the table's cells in the script produce an error. <br><br>As an example, open Word 2008 and run this script: <br> tell application &quot;Microsoft Word&quot; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;make new table at active document with properties {number of rows:4, number of columns:4} <br> &nbsp;&nbsp;&nbsp;&nbsp...

Splitting one table into multiple tables/tabs
Hi I was wondering if anyone can help me split a table into multiple tables or tabs. If I have a table of 20 customers with various transactions over time all in one table. I'd like to know if it's possible to seperate the table into multiple tables based on the change in customer number and have them broken into multiple tabs without manually creating each tab and then cut and pasting. I really appreciate any help! Thanks! ...

Help Creating XmlNode / XmlAttribute Elegantly
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString" value="server=(local);" /> </appSettings> </configuration> I am using a XmlDocument for my base implementation. I am looking to see if there is a better way to add a new node / attribute than using XmlDocument.InnerXml. I would consider this to be a hack but couldn't really see another way of doing this without definin...

tabls in GP90 database
Does anyone know or have a description or documenation on the tables in the database for GP90? Maybe all I need is the important ones. thanks Within the program itself, Tools > Resource Descriptions Also, there are ERD's on the distribution CD's that you got when you purchased or upgraded the system - you have to install the SDK to get at them. -- Lyle U Adam Clark wrote: > Does anyone know or have a description or documenation on the tables > in the database for GP90? Maybe all I need is the important ones. > > thanks ...

Create external database
Hi all. I need to create an external database (file). On a site I found this code: ------------------------------------------------------ Function CreateLinkedExternalTable(strTargetDB As String, strProviderString As String, strSourceTbl As String, strLinkTblName As String) As String 'strTargetDB = Source Database Name 'strProviderString = Not used, currently hard coded 'strSourceTbl = Source Table name in the database we are linking too. 'strLinkTblName = Table name we would like to see in the Access Database. Dim catDB As ADOX.Catalog Dim tblLink As...

How to create pie chart with %
I have got a problem that I don't if excel could help me to calculate the % within a column and draw a pie chart. My case is I have a column containing a series of numbers. e.g. 1,4,8,1,3,9,11,2,4,5,6,.........etc I want to draw a pie chart that showing 1-3 , 4-6, 7-9, >9 with the corresponding % inside that column. Can anyone tell me how can I make it ? Ray - You need to calculate the frequencies in your data. Let's assume your data is in A1:A12. In B1:B3 enter these numbers, the upper limits on the groupings: 3 6 9 You can enter ">9" into B4 witho...

Email address not created when a new user is created
All, This issue recently happened in my company. Upon creating a new user, the policy was set to create the smtp and X400 address automaticaly. Now when we create a user the smtp and x400 addresses are not created, and when attempting to setup the new user in outlook, the address cant be found. We are using exchange 2003 SP1 on Win2k3 servers. On Wed, 13 Jul 2005 06:49:07 -0700, "Bryan" <Bryan@discussions.microsoft.com> wrote: >All, >This issue recently happened in my company. Upon creating a new user, the >policy was set to create the smtp and X400 addres...

Continuous form record number
I have a form whose default view is 'continuous form'. Then when I click a button I need to delete the record where the mouse is (was just) placed. How can I find out the record number? Alternatively any idea is welcome. Thanks Henry "H. Martins" <hjrmartins@gmail.com> wrote in message news:b4ab14e1-51c6-4c16-8a78-bc7df76670de@k31g2000vbu.googlegroups.com... >I have a form whose default view is 'continuous form'. > > Then when I click a button I need to delete the record where the mouse > is (was just) placed. > > Ho...

Exchange 2010 MRM, no log files being created
I'm hoping someone can help me with this issue....it has been driving me crazy for days. I have enabled MRM logging on our exchange server, and I can see that some of the policies are working when I run start-managedfolderassistant. We have a retention policy tag on the deleteditems folder, and this does work. The problem is I am not getting any files in the MRM log directory. C:\Program Files\Microsoft\Exchange Server\V14\Logging\Managed Folder Assistant Events 9021 and 9022 are logged in the Application log, but where are the files? Below is the output of my mai...

when form created
I have a form which was created by someone else (not a form template) which is like a questionnaire with empty boxes to be completed. When the boxes are typed in all the margins move to accommodate the words being typed. Is there a way to fix/lock the original form and then just fill in the blank boxes? I suspect this is set up as a table with auto resizing enabled. Displaying table gridlines (Table | Show Gridlines) will help you see what you're dealing with. Then select the table, go to the Table tab of Table Properties, click Options, and clear the check box for "A...

Creating a Brochure
How do you create a 3-column brochure from scratch for Publisher 2002? I can only find the directions for the 2003 version. Quick help would be appreciated, project is due Monday. Create a three-panel or four-panel folded publication http://office.microsoft.com/en-us/assistance/HP011646681033.aspx Scroll down to the section that says "Build a three-panel or four-panel publications from scratch." -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Derek" <Derek@discussions.microsoft.com> wrote in message news...

Users mailboxes not created when user created
I have a problem that recently just started happening on my exchange 2003 server. When i create a new user account and create the mailbox for exchange, once im done, the mailbox isnt created, adn if you go into the properties of the user account adn go to the exchange email address tab, there isnt an smtp or an x.400 address listed. I am having to manually create and add these, adn then go delete the exchange mailbox and recreate it. This is really annoying and would love to know if anyone has any ideas of how to fix it. Thanks Jason In news:9F836A43-98BF-435A-AA43-AFF10124BE3F@micro...

Tab Sequence? #2
tab sequence? Is there a way to set the order in which cells are highlighted when pressing the tab key? i.e. I have a cell in which data is entered, and then a button which fires a macro next to it. After entering the data I would like to be able to tab out of the cell and have the button highlighted such that pressing enter on the keyboard would trigger the button - much like a web page. Any suggestions? --- Message posted from http://www.ExcelForum.com/ I don't think you can do what you want. Excel allows for very little control over the tab sequence of cells. Moreover, buttons ...