0

Respected Friends..

I need help from your side..
Im using Visual Basic 6.0 with MS Access, I wish to create a automatic serial number for my program, It will show HITE001.. HITE002...HTTE003... same time it will show in form load stage it will automatically show in combo box( last record + 1). Example last record is HITE004, i need HITE005 on form load stage..

Pls my friends help me...

Thanks in avance..
Bala. R

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by AndreRet
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.