Hi,
I'm currently using vb6. i need help.
How can I increment a number in a textbox/label everytime when the form is loaded?
Suppose company_id
I want that first time when the form gets loaded Customer_id should appear in the textbox/label as C01.
Second time it should appear as C02.
Third time C03 and vice versa.
Please help.

Hi,
Are you using Database? and Company_id is a Field?

Hi,
Are you using Database? and Company_id is a Field?

yess...sql.
it is possible we can do auto increment in the database right?but it will just add 1 by 1 and only using 1,2,3 n so on..i want it to be in the other format like C01,C02 and so on..so we must do the coding in the form right?

Yes, Auto increment is possible, but it should be a number, i Think so. But in your case You have mixed the Number and String. So you have to do

> Get the Last Company_id
> Split it into String and Number ( C01 as C and 01)
> Then Increment the Value of Number
> Finally Concatenate the Values

If "C" prefix is fixed for all ID then the extraction is easy.

To extract Use Left () or Mid() function and to Format numbers use Format() function in final concatenation

Yes, Auto increment is possible, but it should be a number, i Think so. But in your case You have mixed the Number and String. So you have to do

> Get the Last Company_id
> Split it into String and Number ( C01 as C and 01)
> Then Increment the Value of Number
> Finally Concatenate the Values

If "C" prefix is fixed for all ID then the extraction is easy.

To extract Use Left () or Mid() function and to Format numbers use Format() function in final concatenation

ok thanx...err can u give an example with the code?tq so much

i m with u selvaganapathy, Select Max of Company_id , split it between character and number then increment number with 1.

Sure!

Private Function GetNextID(sID As String) As String
   Dim i       As Integer
   Dim sTmp    As String
   
   sTmp = Mid(sID, 2)
   i = Val(sTmp) + 1
   sTmp = "C" & Format(i, "0#")
   GetNextID = sTmp
End Function

To use this
First Get Last Company ID and Pass it to this function

MsgBox GetNextID ("C01")

ok it works..thanx a lot.........

Sure!

Private Function GetNextID(sID As String) As String
   Dim i       As Integer
   Dim sTmp    As String
   
   sTmp = Mid(sID, 2)
   i = Val(sTmp) + 1
   sTmp = "C" & Format(i, "0#")
   GetNextID = sTmp
End Function

To use this
First Get Last Company ID and Pass it to this function

MsgBox GetNextID ("C01")

allo...err how is the coding to get last Company ID from sql database?is Company ID must be set to primary key?

>> how is the coding to get last Company ID from sql database?
Use sql statement :

Select Max(field) from tablename

.
selvaganapathy was given the best answer to split company_id.

Hi,

I'm currently using VB 6.0 in front hand and ORACLE 8i IN back hand, i need help.

How can I increment a MOVEMENT TICKET NO. (MT_NO) i.e. ITS TYPE IS VARCHAR i.e. (L/08-09/MT_NO) & (M/08-09/MT_NO) BOTH at a time in TWO DIFFERENT TEXT BOXES everytime when the form is loaded?

Suppose I want that first time when the form gets loaded MOVEMENT TICKET NO. (VARCHAR) i.e. (L/08-09/MT_NO) & (M/08-09/MT_NO) should appear in the TWO DIFFERENT textbox .

ONE FOR L/08-09/MT_NO
&
OTHER FOR M/08-09/MT_NO


Second time it should INCREMENT the MT_NO in both the text boxes and so on.

PLEASE HELP.
early reply is awaited

DEEPAK ANAND

plz tell me the code of vb6 when i add new record to the database it auto increment the number in id textbox

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.