| | |
auto increment number/id
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2008
Posts: 7
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Jul 2008
Posts: 7
Reputation:
Solved Threads: 0
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
> 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
KSG
•
•
Join Date: Jul 2008
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
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.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
Sure!
To use this
First Get Last Company ID and Pass it to this function
VB Syntax (Toggle Plain Text)
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
MsgBox GetNextID ("C01")
KSG
•
•
Join Date: Jul 2008
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
Sure!
VB Syntax (Toggle Plain Text)
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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 :
.
selvaganapathy was given the best answer to split company_id.
Use sql statement :
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Select Max(field) from tablename
selvaganapathy was given the best answer to split company_id.
Last edited by Jx_Man; Jul 23rd, 2008 at 12:50 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
![]() |
Similar Threads
- How to generate auto increment number? (VB.NET)
- Auto increment (Oracle)
- How to auto increment reference number with char(9)? (VB.NET)
- How to auto increment? (ASP.NET)
- Need to know how to create a database that will generate a random number (Database Design)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Problem in form resize
- Next Thread: Pass a text file through a batch file
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






