To get the next number, use the following -
Dim oConn As ADODB.Connection
Dim oRs As ADODB.Recordset
'Using MS Access database...
Dim sConn As String
Dim xCount As Integer
Dim oConn As New ADODB.Connection 'Declare a new connection...
Dim oRs As New ADODB.Recordset 'Declare a new recordset...
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\YourDatabaseNameHere.MDB;Persist Security Info=False"
oConn.Open sConn
oRs.Open "SELECT * FROM YourTableNameHere", oConn, adOpenStatic, adLockOptimistic
If oRs.BOF = True Or oRs.EOF = True Then
'No records exist...
xCount = 1
Text1.Text = xCount
Else
xCount = oRs.Recordcount + 1
Text1.Text = xCount
oRs.Close
oConn.Close
End If
This will however not be the ideal way to get a serial number for your application. The ideal way to do this is to start adding registry values by generating random serial numbers. This is quite advanced, so I will not go into it in this thread.