Results 1 to 4 of 4
  1. #1
    gem is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    2

    creating an ID number in access

    at the moment we have been given this problem where we have to incoporate a Dmax function into the following code



    IDnumber = Left(Firstname, 3) + Left(Lastname, 2)

    from this code the ID number creates something that looks like this

    gembl

    however i need a four digit number after this ID, for every different ID i need the numbers to increase by one the following code was given to us to do in Got Focus but this did not work

    IDnumber = Left(Firstname, 3) + Left(Lastname, 2) + Trim(Str(DMax("right(IDnumber,4)","Customer tbl")+1))
    Please help me

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    You can do that, but

    - is this for human communications and use
    - is this to identify records for Access (because Access can use a different scheme very efficiently and guarantee unique numbers)
    - is the increase by 1 for something special -- please describe

    Why this particular setup is the basic question?

  3. #3
    gem is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    2
    Thank you for replying but I have solved the problem it ended up being as followed


    Private Sub generateID_Click()
    Dim TextPart As String
    Dim NumberPart As String
    'Check that the user has entered the required information
    If IsNull(Firstname) Then Exit Sub
    If IsNull(Surname) Then Exit Sub
    If Len(Firstname) < 3 Then Exit Sub
    If Len(Surname) < 2 Then Exit Sub

    TextPart = Left(Firstname, 3) + Left(Surname, 2)
    NumberPart = DMax("Right(ID_number,4)", "Customertbl")
    NumberPart = NumberPart + 1
    ID_Number = TextPart & NumberPart
    End Sub


    not simple but I got there in the end
    It is for human use, but it is for my A Level Coursework

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Glad you have it working as you need.

    One question -

    Why do you use the + in this TextPart = Left(Firstname, 3) + Left(Surname, 2),
    but the & in this ID_Number = TextPart & NumberPart

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 24
    Last Post: 09-01-2010, 02:09 PM
  2. Replies: 1
    Last Post: 06-30-2010, 07:18 AM
  3. Help On Creating Automatic of a Serial Number
    By lm_lopes in forum Programming
    Replies: 4
    Last Post: 03-10-2010, 06:47 AM
  4. creating automated ticket number
    By speak2des in forum Access
    Replies: 1
    Last Post: 02-25-2010, 11:32 AM
  5. Replies: 1
    Last Post: 01-31-2009, 10:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums