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: - Public Function GeneratePONumber()
-
Dim MyInitials, MyName, MyNames
-
Dim strFname, strLname, strInitials As String
-
Dim intHighPO As Integer
-
-
'INITIAL GENERATOR
-
'Determines who is logged in, and generates user's initials
-
strFname = DLookup("username", "users", "userid = " & intAuthUserId)
-
strLname = DLookup("userlastname", "users", "userid = " & intAuthUserId)
-
MyNames = Split(strFname & " " & strLname, " ")
-
For Each MyName In MyNames
-
If Len(MyName) > 0 Then MyInitials = MyInitials & UCase(Left(MyName, 1))
-
Next
-
'END INITIAL GENERATOR
-
-
For Each OrderPONumber In orders
-
'FIND HIGHEST PO NUMBER BEGINNING WITH MyInitials
-
Next
-
-
'ADD INITIALS AND LAST PO NUMBER+1
-
strNewPONumber = MyInitials & intHighPO + 1
-
-
End Function
6 1170
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"
Hi
Make a composite key for that, combination of username and another key (set to autonumber)...
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.
hi
following code should help you - Const MyInitials = "JC"
-
Dim strArr(10) As String
-
Dim i As Integer
-
'Fill array
-
For i = 0 To 9
-
strArr(i) = MyInitials & Format(i, "0000#")
-
Next
-
Dim intMax As Integer
-
intMax = 0
-
'find maximum
-
For i = 0 To 9
-
If Val(Replace(strArr(i), MyInitials, "")) > intMax Then
-
intMax = Val(Replace(strArr(i), MyInitials, ""))
-
End If
-
Next
-
MsgBox MyInitials & Format(intMax + 1, "0000#")
-
regards
manpreet singh dhillon hoshiarpur
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
Cool. I'm sure we'll all be interested to hear what direction you take.
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
|
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...
|
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++){...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |