cmd Button that auto generates a string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to do the following: have a cmd button that will auto generate a
string starting with "CRM" and have 4 digits after (never repeating) such as
CRM0001...0002 and so on. I would like this to populate a text box (acct#)
that I have.

Does anyone know how to do this or if it is even possible?
 
How would you create the string? That is the main part that I am having
trouble with.

Thanks
 
What do you do with the contenets of the text box once it is populated? You
said a non repeating number, but we need a way to know what the last high
number was, I think.
 
I will be storing this value in a table. I have a table of real "live
accounts" starting with EP. The CRM... are just possible leads but they can
turn into live accounts. So when the user gets the lead they will click the
button and it will autogenerate a number then they can fill out the rest of
the form. After that they can save it and later pull it back up to either
change it into a live account or make future notes.
 
Dim X as integer

x=0

In the procedure
x=x+1
textbox.text="CRM" & lpad(ltrim(rtrim(str(x))),"0",3)
 
Where do I declare the Dim X as Integer part? I put it on in my procedure and
it brings back CRM1 everytime. I quickly through a msgbox in just to test.

Private Sub cmdAGenerate_Click()
Dim stAutoStr As String
Dim X As Integer

X = 0
X = X + 1
stAutoStr = "CRM" & X
MsgBox (stAutoStr)
End Sub
 
I will be storing this value in a table. I have a table of real "live
accounts" starting with EP. The CRM... are just possible leads but
they can turn into live accounts. So when the user gets the lead they
will click the button and it will autogenerate a number then they can
fill out the rest of the form. After that they can save it and later
pull it back up to either change it into a live account or make future
notes.

Hi James,

If you had a yes/no field in this table indicating whether this
account is a lead of a "live account" and another field with the
number without alpha characters you could always put the
EP0001 and CRM0002 together and creating the next number would be
trivial.

Are there ever duplicate numbers in EP and CRM or do you just
change the prefix?

It can be done with the *9999 string but it is a little more involved.
 
I am not sure if this will work like this. The table that I have right now
has 1000 active accounts. There are no leads (CRMs) in this table. The agent
gets leads by email and will start putting them into the db so that we can
track them. That is why I was looking for a way so that he/she could hit a
button and it would automatically generate a number. The only way of doing
this that I could think of would be to

1. Query the table for accounts starting with CRM
2. Add 1 to the last account

Of course this is easy to say, but I have no clue how to do this.
 
I am not sure if this will work like this. The table that I have right
now has 1000 active accounts. There are no leads (CRMs) in this table.
The agent gets leads by email and will start putting them into the db
so that we can track them. That is why I was looking for a way so that
he/she could hit a button and it would automatically generate a
number. The only way of doing this that I could think of would be to

1. Query the table for accounts starting with CRM
2. Add 1 to the last account

Of course this is easy to say, but I have no clue how to do this.

James,

Here's some code written by Klatuu that should give you an idea
or two on doing what you are asking for:
______________________________________________________
strNext = DMAX("[FieldNameHere]","TableNameHere")
intNext = Cint(Replace(strNext, "L-",""))
strNext=left(strNext, 2) & format(intNext + 1, "0000")
______________________________________________________

I guess I should back up to the beginning. What do you need the
"EP9999 or CRM9999" for? I got a little ahead of myself there.
To properly assist you in what you were asking for I should have
started off with why do you need this particular numbering system.
Right off the bat it has a limit of 10,000 without some additional
codine and maybe a little resturcturing of the field.

Again, are there ever duplicate numbers in EP and CRM or do you just
change the prefix?
 
Back
Top