Auto Generated ID

ejvitor

Member
Joined
Oct 22, 2010
Messages
5
Location
Philippines
Programming Experience
1-3
How to auto generate once i click the add button actually autonum sub procedure is a part of add button click event here's my code for auto-increment below:

Sub autonum()
Dim cnSet As New ADODB.Connection
Dim rsSet As New ADODB.Recordset
Dim nums As Integer

Call connection(cnSet, Application.StartupPath & "\dbsi.mdb")
Call recordset(rsSet, cnSet, "SELECT * FROM t_Customers")
If rsSet.RecordCount = 0 Then
Me.txtCustomerNo.Text = "CUST-001"
Else
rsSet.MoveLast()


Me.txtCustomerNo.Text = "CUST-" & Format(Val(nums) + 1, "000#")
End If
End Sub

any help?
 
First things first, get rid of all that ADODB stuff. You're using VB.NET now, not VB6, so use VB.NET. You should be using ADO.NET for your data access.

As for auto-generating IDs, you should just let the system do that for you. If you use the AutoNumber data type then Access will generate an ID when the record is inserted. If you want to display the value in a specific format then do so, when you display it.
 
hey, thanks for advice, i am newbie in vb.net since i am currently use vb6
but i don't how to use ADO.net so please let me know how ADO.net works
 
Last edited:
Back
Top