Hi! I found this code in one of the threads here
I converted it into an access kind of code(?) and unfortunately, it won't increment, nor find the top/max in my database. Someone please help?
`
Private Function GenID() As String
Dim dr As OleDbDataReader
Dim com As OleDbCommand
Dim value As String = "2021000"
Dim ID As String
Try
con.Open()
com = New OleDbCommand("SELECT TOP 1 <studno> FROM record ORDER by <studno> DESC", con)
dr = com.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows Then
dr.Read()
value = dr.Item("<studno>")
End If
value += 1
If value <= 9 Then 'Value is between 0 and 10
value = "202100" & value
ElseIf value <= 99 Then 'Value is between 9 and 100
value = "20210" & value
ElseIf value <= 999 Then 'Value is between 999 and 1000
value = "2021" & value
End If
Catch ex As Exception
If con.State = ConnectionState.Open Then
con.Close()
End If
value = "2021000"
End Try
Return value
End Function
Private Sub addRecords_Load(sender As Object, e As EventArgs) Handles MyBase.Load
studno.Text = GenID()
End Sub
`