Private Sub AutoRunnumber()
Dim Runnumber As String
Dim sqlRunnumber As String
Dim RsRunnumber As New ADODB.Recordset
sqlRunnumber = "select top 1 certify_no from [SAcc_Trans] where left(certify_no," & Len(cmbBook.Text) + 2 & ")='" & Trim(cmbBook.Text) & Format(DtDate.Value, "yy") & "' and book_id='" & Trim(cmbBook.Text) & "' order by certify_no desc"
With RsRunnumber
If .State = adStateOpen Then .Close
.ActiveConnection = Conn
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
.Open sqlRunnumber
If .RecordCount = 0 Then
Runnumber = "00001"
ElseIf Trim(!certify_no) = "" Or IsNull(!certify_no) Then
Runnumber = "00001"
ElseIf Mid(Trim(!certify_no), 14, 5) = "99999" Then
Runnumber = "00001"
Else
Runnumber = Format(Val(Right(Trim(!certify_no), 5)) + 1, "00000")
End If
End With
txtCertify_no.Text = Trim(cmbBook.Text) & Format(DtDate.Value, "yy") & Runnumber
End Sub
Tag : .NET, Win (Windows App), VS 2010 (.NET 4.x), VS 2012 (.NET 4.x), VS 2015 (.NET 4.x), Windows