Need to a text field a value made up of 3 letters + 00000000 +01 through 999999 and have the total length to be no more than 20 long

Need to a text field a value made up of 3 letters + 00000000 +01 through 999999 and have the total length to be no more than 20 long
frank_guessAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

William BlakeDeveloperCommented:
I am not sure I understand what you need.  Are you saying you want something that will automatically generate and store a string value of any three letters and 00000000 and 01 -> 999999
IE:
ABC0000000001
ABC0000000002
ABC0000000003
[...]
ABC00000000999999

Is this what you are looking for?  If so that should be a pretty easy function to write.
0
frank_guessAuthor Commented:
I am looking for a way to to put a string together to place into a text field.
Field name is Vendor_Number
I have an autonumber field called VendorID
and I need the Vendor_Number to look like this - VEN0000001
This value represents the number FIRST auto number with the VEN0000001  - 10 zeros in between the VEN0000000001
Then from that point on the right side would end with the VendorID number but be right justified so the positions and zeros will always have no more thank 10 spaces so the first number is VEN0000000001 and 999 would be VEN0000000999 if the number grows to VEN0000099999 then the number of zeros goes down but the number of spaces and numbers after the VEN are the 10 spaces.
0
William BlakeDeveloperCommented:
Ok I understand.  A couple of questions, is this vendor number being placed on a form field? Is this form opened by a few people at once or only one person?

And to be clear it needs to be VEN + 10 digits.  Right? You said one thing above and typed another as an example.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

hnasrCommented:
"no more than 20 long"
The maximum string is ABC00000000999999 which is 17 long.

Try this in the immediate window:
The idea is to concatenate the 3 characters + 8 0s + right 6chars (from 5 0s + the number)
? "ABC" & "00000000" & right("00000" & 99,6)

To use it in code: Try the following statements  in immediate window.

c="ABC"
z="00000000"
f="00000"
n=99
? c & z & right(f & n,6)
0
frank_guessAuthor Commented:
William sorry I made a mistake but yes max string lenght is 20 long.
that includes VEN + 17 Zeros and numbers
0
frank_guessAuthor Commented:
Sorry hnasr You are correct with my example.

So it looks like this:

A = "VEN"
B = "000000000000000000000"
C = [VendorID] - this starts at 1 and goes to 9999999

The value now looks like "VEN00000000009999999"
The number of zeros decrease as the number of 9's increase.
0
William BlakeDeveloperCommented:
Ok, here is some VBA that might get you started.  It does a DMAX lookup to get the highest Vendor ID in a table (I assume you have some sort of vendors table).  Then strips off the VEN prefix and converts the id to a number and adds one.  It then converts it back to a string and gets a string length which using an if else if statement adds the apppriate number of zeros between VEN and the Counter.  Let me know if this goes in the right direction.  If you need it to appear on a form, that can easily be done too (although I might want this function to fire when the form is submitted to make sure the vendor ID remains unique.

Dim vendorID As String
Dim vendorIDNum As String
Dim idVal As Integer
Dim vendorIDLen As Integer
' get the max vendor id from a table
vendorID = DMax("vendorID", "table1")
' split off the ven prefix
vendorIDNum = Mid(vendorID, 4)
'convert to a number
idVal = CInt(vendorIDNum)
' add one to it
idVal = idVal + 1
'convert back to string
vendorID = CStr(idVal)
'check the length
vendorIDLen = Len(vendorID)

If vendorIDLen = 1 Then
    vendorID = "VEN000000000" & vendorID
ElseIf vendorIDLen = 2 Then
    vendorID = "VEN00000000" & vendorID
ElseIf vendorIDLen = 3 Then
    vendorID = "VEN0000000" & vendorID
ElseIf vendorIDLen = 4 Then
    vendorID = "VEN000000" & vendorID
ElseIf vendorIDLen = 5 Then
    vendorID = "VEN00000" & vendorID
ElseIf vendorIDLen = 6 Then
    vendorID = "VEN0000" & vendorID
ElseIf vendorIDLen = 7 Then
    vendorID = "VEN000" & vendorID
ElseIf vendorIDLen = 8 Then
    vendorID = "VEN00" & vendorID
ElseIf vendorIDLen = 9 Then
    vendorID = "VEN0" & vendorID
ElseIf vendorIDLen = 10 Then
    vendorID = "VEN" & vendorID
End If

Open in new window


I did the above while I thought it was 10 digits between the VEN and counter.  You will have to adjust the If else if to compensate.
0
ChloesDadCommented:
You can do it in one line

VendorID = "VEN" + right("0000000000000000" & CStr(idVal),17)

This will add the right most 17 characters of 0000000000000000000000xxx to the initial string
0
ChloesDadCommented:
In .net you can do it with the .Tostring also

VendorID = "VEN" & idval.tostring("00000000000000000")
0
hnasrCommented:
Try this:
A = "VEN"
B = "00000000000000000"
You may use:
B = string(17,"0")
C= [VendorID]
txt = A  & RIGHT(B & C , 17)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
frank_guessAuthor Commented:
Thanks to everyone.  I will review and let you know in the morning.  Got to go and pick up something before the store closes.
0
frank_guessAuthor Commented:
All solutions offered except for the Dot Net, sorry I have not got into Dot Net yet.  This is in an Access 2010 database system and I have not yet moved it to an Internet or Intranet offering but thank you for your insight.  William Blake your solution works great when I want to use a button to run the code.  CholesDad The one line works great too.  Hnasr your code works great as well.  You all have done a great job for me.
I forget to add  that what I needed was a way to do these in a one line by running a query but I figured that out when I remembered a small utility I built a year ago to develop a modulo and then call it within the query.  Thanks all
0
hnasrCommented:
Welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.