473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Please help with alphanumeric number handling

I'm creating a function that will autoincrement a purchase order number. The number is the logged in users initials followed by four numbers (eg. JC0001). How would I go about determining the highest existing number with the prefix of the person who is creating the new order?

Thanks, Justin

Here is my code, I apologize if it is a bit elementary:

Expand|Select|Wrap|Line Numbers
  1. Public Function GeneratePONumber()
  2.     Dim MyInitials, MyName, MyNames
  3.     Dim strFname, strLname, strInitials As String
  4.     Dim intHighPO As Integer
  5.  
  6.     'INITIAL GENERATOR
  7.     'Determines who is logged in, and generates user's initials
  8.     strFname = DLookup("username", "users", "userid = " & intAuthUserId)
  9.     strLname = DLookup("userlastname", "users", "userid = " & intAuthUserId)
  10.     MyNames = Split(strFname & " " & strLname, " ")
  11.     For Each MyName In MyNames
  12.         If Len(MyName) > 0 Then MyInitials = MyInitials & UCase(Left(MyName, 1))
  13.     Next
  14.     'END INITIAL GENERATOR
  15.  
  16.     For Each OrderPONumber In orders
  17.         'FIND HIGHEST PO NUMBER BEGINNING WITH MyInitials
  18.     Next
  19.  
  20.     'ADD INITIALS AND LAST PO NUMBER+1
  21.     strNewPONumber = MyInitials & intHighPO + 1
  22.  
  23. End Function
Feb 12 '08 #1
6 1170
Killer42
8,435 Expert 8TB
I'd suggest you use the Max database function to find the maximum value that is
Like "JC*"
Or depending on the database, the wildcard character might be %, which would make:
Like "JC%"

You might also use a Between clause, such as
Between "JC0001" AND "JC9999"
Feb 12 '08 #2
lotus18
866 512MB
Hi

Make a composite key for that, combination of username and another key (set to autonumber)...
Feb 13 '08 #3
Killer42
8,435 Expert 8TB
Something I forgot to mention. This scheme looks as though has a fundamental flaw which may cause problems later. That is, the inability to handle multiple people with the same intials.
Feb 13 '08 #4
9815402440
180 100+
hi

following code should help you
Expand|Select|Wrap|Line Numbers
  1. Const MyInitials = "JC"
  2. Dim strArr(10) As String
  3. Dim i As Integer
  4. 'Fill array
  5. For i = 0 To 9
  6.     strArr(i) = MyInitials & Format(i, "0000#")
  7. Next
  8. Dim intMax As Integer
  9. intMax = 0
  10. 'find maximum
  11. For i = 0 To 9
  12.     If Val(Replace(strArr(i), MyInitials, "")) > intMax Then
  13.         intMax = Val(Replace(strArr(i), MyInitials, ""))
  14.     End If
  15. Next
  16. MsgBox MyInitials & Format(intMax + 1, "0000#")
  17.  
regards
manpreet singh dhillon hoshiarpur
Feb 13 '08 #5
Thanks for the help. I enjoy seeing how many different ways there are to accomplish the same objective with code. I thought about the composite key method however, I wanted to keep the numbers sequential per user. Also, thanks for pointing out the fundamental flaw, I'm still trying to decide how to address this. I will reply back when I figure it out.

Thanks again,

Justin
Feb 13 '08 #6
Killer42
8,435 Expert 8TB
Cool. I'm sure we'll all be interested to hear what direction you take.
Feb 13 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Bob | last post by:
Sorting the following alphanumerics using myArray.sort(): 04-273-0001 04-272-0001 04-272-0003 04-272-0001 04-273-0001 Results in:
11
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into...
9
by: fooboo | last post by:
Does anyone know if a easier way (built in function, or something) that can verify that a string is an alphanumeric number? Here is what I am doing now: for(i=0; i < strlen(temp); i++){...
3
by: Webdiyer | last post by:
I want to integrate SecurID two-factor authentication system of the RSASecurity.inc into our asp.net application,but I get into trouble when trying to call the API functions of the ACE Agent,I got...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
11
by: Bruce Lawrence | last post by:
Ok, I'm baffled... I'm making a query in access 97 between 2 tables. There is a field in both tables called "DWGNO". OPENORD has a record with a DWGNO of "00000012345" DIEDATA has a record...
7
by: JJ | last post by:
To validate a password as the user is registering I want to use a regular expressio validator. I got this one from the Microsoft web site for validating a password of at least 7 characters, with...
7
by: kanepart2 | last post by:
Hey all, I have to validate a textbox in windows forms for alphanumeric characters such that non alphanumeric key presses are ignored. Some help would be appreciated
4
by: cpptutor2000 | last post by:
Could some C guru provide some hints on my problem? I am trying to sort an array of character strings, where each string contains lowercase, uppercase, digits as well as non-alphanumeric characters...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.