PC Review


Reply
Thread Tools Rate Thread

adding sequential numbers to a group of records

 
 
vsoeiro
Guest
Posts: n/a
 
      7th Oct 2008
hi all, need your help on this,

I need to add a sequential number to all records in a given table, starting
at a given number. I think i should do something like this:

dim intStartingValue as Integer
'start at 21, for instance
intValue = 20

For Each element In group
intValue = intValue + 1
<field to be updated> = intValue
Next

My problem is to indicate element as being the records, and group being the
table I want to update. Can someone please help on this, or suggest a better
aproach?

Thanks,

Vasco

 
Reply With Quote
 
 
 
 
dch3
Guest
Posts: n/a
 
      7th Oct 2008
What is the specific reason why you want sequential numbers?

When working with a database, there is no guarantee that the database engine
will return records in any particular order unless you use sorting in your
query - and then you can always get mixed results based on the specific
sorting that you use and situations where a record has nearly the same values
for the fields on which you sort.

"vsoeiro" wrote:

> hi all, need your help on this,
>
> I need to add a sequential number to all records in a given table, starting
> at a given number. I think i should do something like this:
>
> dim intStartingValue as Integer
> 'start at 21, for instance
> intValue = 20
>
> For Each element In group
> intValue = intValue + 1
> <field to be updated> = intValue
> Next
>
> My problem is to indicate element as being the records, and group being the
> table I want to update. Can someone please help on this, or suggest a better
> aproach?
>
> Thanks,
>
> Vasco
>

 
Reply With Quote
 
vsoeiro
Guest
Posts: n/a
 
      7th Oct 2008
thanks for your reply. I'll try to make the answer simple: the reason is I
have a local table in my database where I, provisionally, keep and edit some
records, before adding them to a sharepoint list, linked to my database.
before adding those records, I need one of their fields to start where the
last in the sharepoint list ended. for instance, the last is 20, I want my 4
records in the proviosional table to be 21, 22, 23 and 24 before adding them
to te list and deleting them from the provisional table. hope i have made
myself clear.

"dch3" wrote:

> What is the specific reason why you want sequential numbers?
>
> When working with a database, there is no guarantee that the database engine
> will return records in any particular order unless you use sorting in your
> query - and then you can always get mixed results based on the specific
> sorting that you use and situations where a record has nearly the same values
> for the fields on which you sort.
>
> "vsoeiro" wrote:
>
> > hi all, need your help on this,
> >
> > I need to add a sequential number to all records in a given table, starting
> > at a given number. I think i should do something like this:
> >
> > dim intStartingValue as Integer
> > 'start at 21, for instance
> > intValue = 20
> >
> > For Each element In group
> > intValue = intValue + 1
> > <field to be updated> = intValue
> > Next
> >
> > My problem is to indicate element as being the records, and group being the
> > table I want to update. Can someone please help on this, or suggest a better
> > aproach?
> >
> > Thanks,
> >
> > Vasco
> >

 
Reply With Quote
 
vbasean
Guest
Posts: n/a
 
      7th Oct 2008
a couple questions:
1) is the access table mimicking the sharepoint list? If so, then the table
should have the correct last seed. If that's the case, try using the 'DMax'
function to retreave the greatest seed value and add one to it.

2) if this is occuring in a form you can use the form's 'Before Update'
event to add the new seed number to each record as neccessary.

3) if you are looking to just take the 'unassigned' items in your table and
issue them the new seed numbers based off of the seed number you issue. i.e.
last number was 20 so you want 21, 22, 23, ... etcetera. Then iterate a
recordset:

Private Sub UpdateMyRecords(seed as integer)
Dim rs as Recordset
Dim db as Database
Set db = CurrentDb
set rs = db.openrecordset([name or recordset to update]) 'a filtered recordset
'so you only get records that need updating, maybe a query
rs.MoveFirst
do while not rs.Eof
With rs
..Edit
rs.[number you want to add] = seed
..Update
End with
seed = seed + 1
Loop
End Sub

you can issue this Subroutine anywhere you want
UpdateMyRecords(21) 'where '21' is the next number to start at

"vsoeiro" wrote:

> hi all, need your help on this,
>
> I need to add a sequential number to all records in a given table, starting
> at a given number. I think i should do something like this:
>
> dim intStartingValue as Integer
> 'start at 21, for instance
> intValue = 20
>
> For Each element In group
> intValue = intValue + 1
> <field to be updated> = intValue
> Next
>
> My problem is to indicate element as being the records, and group being the
> table I want to update. Can someone please help on this, or suggest a better
> aproach?
>
> Thanks,
>
> Vasco
>

 
Reply With Quote
 
vbasean
Guest
Posts: n/a
 
      7th Oct 2008
rs.[number you want to add] = seed

this should be [field you want to update]

didn't mean to confuse anyone.

"vbasean" wrote:

> a couple questions:
> 1) is the access table mimicking the sharepoint list? If so, then the table
> should have the correct last seed. If that's the case, try using the 'DMax'
> function to retreave the greatest seed value and add one to it.
>
> 2) if this is occuring in a form you can use the form's 'Before Update'
> event to add the new seed number to each record as neccessary.
>
> 3) if you are looking to just take the 'unassigned' items in your table and
> issue them the new seed numbers based off of the seed number you issue. i.e.
> last number was 20 so you want 21, 22, 23, ... etcetera. Then iterate a
> recordset:
>
> Private Sub UpdateMyRecords(seed as integer)
> Dim rs as Recordset
> Dim db as Database
> Set db = CurrentDb
> set rs = db.openrecordset([name or recordset to update]) 'a filtered recordset
> 'so you only get records that need updating, maybe a query
> rs.MoveFirst
> do while not rs.Eof
> With rs
> .Edit
> rs.[number you want to add] = seed
> .Update
> End with
> seed = seed + 1
> Loop
> End Sub
>
> you can issue this Subroutine anywhere you want
> UpdateMyRecords(21) 'where '21' is the next number to start at
>
> "vsoeiro" wrote:
>
> > hi all, need your help on this,
> >
> > I need to add a sequential number to all records in a given table, starting
> > at a given number. I think i should do something like this:
> >
> > dim intStartingValue as Integer
> > 'start at 21, for instance
> > intValue = 20
> >
> > For Each element In group
> > intValue = intValue + 1
> > <field to be updated> = intValue
> > Next
> >
> > My problem is to indicate element as being the records, and group being the
> > table I want to update. Can someone please help on this, or suggest a better
> > aproach?
> >
> > Thanks,
> >
> > Vasco
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Sequential Numbers to a Query Santi Microsoft Access 1 9th Apr 2010 08:41 PM
Generate Sequential numbers for new records jtidwell Microsoft Access Form Coding 14 4th Jul 2007 06:11 AM
Generate Sequential numbers for new records jtidwell Microsoft Access Getting Started 7 27th Jun 2007 07:04 PM
Re: Group By Sequential Records John Nurick Microsoft Access Queries 1 29th Dec 2006 09:05 AM
Adding sequential records via a Form shrader Microsoft Access Forms 1 1st Jul 2005 07:38 AM


Features
 

Advertising
 

Newsgroups
 


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