View Single Post
  #4  
Old April 29th, 2004, 06:30 AM
John Vinson
external usenet poster
 
Posts: n/a
Default Assigning numbers

On Wed, 28 Apr 2004 11:01:27 -0700, "Fred"
wrote:

Greetings,
I have a project where I have to assign a three-part ID
number to each new entry. The first two parts to
the "number" are typed in by the user. Access is to assign
the numeric part (e.g. 1,2,3...)
e.g. Fred - Ford - 1
Fred - Ford - 2
Fred - Toyota - 1
Freda - Ford - 1
etc.

Has anyone been able to do this?
Please help!


I'd suggest that you keep this ID in three fields, not one; note that
a Primary Key can consist of up to TEN fields. Concatenating it into
one is neither necessary nor desirable.

You can do your data entry with a Form (tables don't have any usable
events for the purpose). Let's say you have fields Who, What, and Num
as above, with controls txtWho, txtWhat, and txtNum; you could put
code in the AfterUpdate event of What like this:

Private Sub txtWhat_AfterUpdate()
If IsNull(Me!txtWho) Then
MsgBox "Fill in a name please!", vbOKOnly
Me!txtWho.SetFocus
End If
If IsNull(Me!txtWhat) Then
MsgBox "Fill in a car please!", vbOKOnly
End If
Me!txtNum = NZ(DMax("Num", "yourtable", "[Who] = '" _
& Me!txtWho & "' AND [What] = '" & Me!txtWhat & "'")) + 1
End Sub

An Autonumber will not really be suitable since it's one series (and
may have gaps at that).

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public