Connecting Tech Pros Worldwide Help | Site Map

Increment by 1 if duplicate text value

  #1  
Old January 23rd, 2006, 09:45 PM
rech340
Guest
 
Posts: n/a
I have a table with the following:

AutoNumber Course Name (a text field)

I want to add a Section Field that increments beginning with 001 all
the way to 999, for Each UNIQUE Course Name.

For Example:

Let's say I have a course Name in this table of "MS Word 2003 Level 1".
In the table, is there any way for Access to assign a Section #
automatically if the text value is duplicated.

Any suggestions would be greatly appreciated

  #2  
Old January 24th, 2006, 03:05 AM
salad
Guest
 
Posts: n/a

re: Increment by 1 if duplicate text value


rech340 wrote:
[color=blue]
> I have a table with the following:
>
> AutoNumber Course Name (a text field)
>
> I want to add a Section Field that increments beginning with 001 all
> the way to 999, for Each UNIQUE Course Name.
>
> For Example:
>
> Let's say I have a course Name in this table of "MS Word 2003 Level 1".
> In the table, is there any way for Access to assign a Section #
> automatically if the text value is duplicated.
>
> Any suggestions would be greatly appreciated
>[/color]
I guess. This could be 1 to many. Create another table with the
tableid for the course and the section field number. Set a flag whether
or not it is a new record in the BeforeUpdate event of the form. If so,
use a For/Next loop to go add 999 Section records.

Or, you could change the CourseName field index to allow duplicates.
Then in the BeforeUpdate event for the form, add something like
If Me.NewRecord Then
Me.Section = NZ(Dmax("Section","YourTableName" _
"CourseName = '" & Me.CourseName & "'") + 1
Endif

Now, if you change a course name, you'd want to update all other course
names to the new course name

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate numbers in "Autonumber" field -- help! Tom_F answers 9 March 20th, 2007 02:15 AM
altering a table to set serial function Prabu Subroto answers 12 November 23rd, 2005 01:30 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 5 November 14th, 2005 12:36 PM
Need HELP / Increment ID (number) for each unique text string tHeRoBeRtMiTcHeLL answers 1 November 13th, 2005 03:05 PM