Connecting Tech Pros Worldwide Help | Site Map

Auto-number text field

  #1  
Old March 11th, 2006, 02:15 AM
John
Guest
 
Posts: n/a
Hi

I need a auto-number field but with a letter prefix like "P1", "P2" etc.
What is the way to achieve this? Is it possible to do this at table level?

Thanks

Regards


  #2  
Old March 11th, 2006, 09:45 PM
salad
Guest
 
Posts: n/a

re: Auto-number text field


John wrote:
[color=blue]
> Hi
>
> I need a auto-number field but with a letter prefix like "P1", "P2" etc.
> What is the way to achieve this? Is it possible to do this at table level?
>
> Thanks
>
> Regards
>
>[/color]
What type is an autonumber? In my Access, it's a LongInt.

You could have a field called ID. To Update it, you could enter
Me.ID = NZ(Dmax("ID","TableName"),0)
Then assign the letter to another field.

You could create a query to concantenate the two to make a Key with the
prefix.
  #3  
Old March 11th, 2006, 11:05 PM
David W. Fenton
Guest
 
Posts: n/a

re: Auto-number text field


"John" <John@nospam.infovis.co.uk> wrote in
news:qNudnVVOHKIRso_ZRVny2A@pipex.net:
[color=blue]
> I need a auto-number field but with a letter prefix like "P1",
> "P2" etc. What is the way to achieve this? Is it possible to do
> this at table level?[/color]

What you really want is two fields acting as a compound key, one an
Autonumber, and the other the appropriate letter.

That is, if you need the Autonumber's to be globally unique. If you
want them to have independent runs for each letter, then you have to
use a long integer and assign it programatically for the subset of
values with the particular letter in the other field.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
  #4  
Old March 12th, 2006, 12:15 AM
Wayne Gillespie
Guest
 
Posts: n/a

re: Auto-number text field


On Sat, 11 Mar 2006 21:30:00 GMT, salad <oil@vinegar.com> wrote:
[color=blue]
>John wrote:
>[color=green]
>> Hi
>>
>> I need a auto-number field but with a letter prefix like "P1", "P2" etc.
>> What is the way to achieve this? Is it possible to do this at table level?
>>
>> Thanks
>>
>> Regards
>>
>>[/color]
>What type is an autonumber? In my Access, it's a LongInt.
>
>You could have a field called ID. To Update it, you could enter
> Me.ID = NZ(Dmax("ID","TableName"),0)
>Then assign the letter to another field.
>
>You could create a query to concantenate the two to make a Key with the
>prefix.[/color]

Small typo Salad ;) it should be -

Me.ID = NZ(Dmax("ID","TableName"),0) + 1


Wayne Gillespie
Gosford NSW Australia
  #5  
Old March 12th, 2006, 07:05 PM
salad
Guest
 
Posts: n/a

re: Auto-number text field


Wayne Gillespie wrote:[color=blue]
> On Sat, 11 Mar 2006 21:30:00 GMT, salad <oil@vinegar.com> wrote:
>
>[color=green]
>>John wrote:
>>
>>[color=darkred]
>>>Hi
>>>
>>>I need a auto-number field but with a letter prefix like "P1", "P2" etc.
>>>What is the way to achieve this? Is it possible to do this at table level?
>>>
>>>Thanks
>>>
>>>Regards
>>>
>>>[/color]
>>
>>What type is an autonumber? In my Access, it's a LongInt.
>>
>>You could have a field called ID. To Update it, you could enter
>> Me.ID = NZ(Dmax("ID","TableName"),0)
>>Then assign the letter to another field.
>>
>>You could create a query to concantenate the two to make a Key with the
>>prefix.[/color]
>
>
> Small typo Salad ;) it should be -
>
> Me.ID = NZ(Dmax("ID","TableName"),0) + 1[/color]

Good catch! It makes sense to have an ID number that is incremented by
1 when added.
[color=blue]
>
>
> Wayne Gillespie
> Gosford NSW Australia[/color]
  #6  
Old March 13th, 2006, 12:05 AM
Dean
Guest
 
Posts: n/a

re: Auto-number text field


Wouldn't that be Me.ID = "P" & NZ(Dmax("ID","TableName"),0)+1

If you want certain number of zeros then you can:

Me.ID = "P" & left$("0000000000" & NZ(Dmax("ID","TableName"),0)+1,8)

This would create a 9 character string P00000001, P00000002,
P00000003, . . . PP00000010, P00000011, etc

  #7  
Old March 13th, 2006, 01:45 AM
David W. Fenton
Guest
 
Posts: n/a

re: Auto-number text field


"Dean" <d@coveyaccounting.com> wrote in
news:1142207618.275465.42360@j52g2000cwj.googlegro ups.com:
[color=blue]
> Wouldn't that be Me.ID = "P" & NZ(Dmax("ID","TableName"),0)+1
>
> If you want certain number of zeros then you can:
>
> Me.ID = "P" & left$("0000000000" &
> NZ(Dmax("ID","TableName"),0)+1,8)
>
> This would create a 9 character string P00000001, P00000002,
> P00000003, . . . PP00000010, P00000011, etc[/color]

You're missing the point.

First off, you shouldn't mix two pieces of information that are
independently meaningful in a single field.

Second, there are two possibilities:

1. global ID sequence, e.g., P0001, X0002, P0003...

2. ID sequence for each letter, e.g., P0001, X0001, P0002...

The former can be done with an Autonumber field plus a letter field,
while the latter cannot.

My main point is that I'd never store both letter and number in a
single field. If you never actually search on the initial letter,
then why is it there in the first place? If you do, then performance
will be vastly improved by using two fields with a compound unique
index.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
  #8  
Old March 13th, 2006, 02:25 AM
Dean
Guest
 
Posts: n/a

re: Auto-number text field


Dave, I agree with you 100%. The original author did not indicated if
the two pieces of information are independently meaningful. What I was
showing was another possibility that expanded on Salad's and Wayne's
posts. There is probably more to the story than the original post.

  #9  
Old March 16th, 2006, 12:25 AM
John
Guest
 
Posts: n/a

re: Auto-number text field


The letter can be in a separate field.

Because the underlying table field is text DMax("[YourField]","YourTable"),
as far as I can tell, brings say 999 as the largest previous number instead
of say 1020 (text comparison instead of numeric comparison)and then adds one
to it thus creating a duplicate id 1000 which is already in the table.

Regards

"Dean" <d@coveyaccounting.com> wrote in message
news:1142216001.551659.321220@p10g2000cwp.googlegr oups.com...[color=blue]
> Dave, I agree with you 100%. The original author did not indicated if
> the two pieces of information are independently meaningful. What I was
> showing was another possibility that expanded on Salad's and Wayne's
> posts. There is probably more to the story than the original post.
>[/color]


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does FullText warning mean any update to text field will not be reflected? John Kotuby answers 2 June 27th, 2008 09:01 PM
radio button make text field equal value of form field mitch-co2 answers 4 July 23rd, 2005 07:06 PM
Insert file data into text field Rob answers 4 July 20th, 2005 12:03 AM
Strange behavior with SQL text field and ADO Parameter....a challenge for the experts (Aaron Bertrand) Dan answers 4 July 19th, 2005 02:04 PM