Public Sub Sub_serialNo()
Dim rs_tmp12 As New ADODB.Recordset
Dim STR_PVNO As String
Set rs_tmp12 = Nothing
rs_tmp12.Open "Select prefix from VoucherTypeMst where Name='JOURNAL VOUCHER'", conn, adOpenDynamic, adLockOptimistic
If Not rs_tmp12.EOF Then
STR_PVNO = BRANCHCODE & rs_tmp12(0) & Format(MONTH(Date), "00") & Format(Day(Date), "00")
End If
If rs_tmp12.State = adStateOpen Then rs_tmp12.Close
rs_tmp12.Open "Select right(max(Voucherno),3) from VoucherMst where VoucherType='JOURNAL VOUCHER' and Voucherdate='" & Format(Date, "mm/dd/yyyy") & "' AND Branchcode='" & BRANCHCODE & "' AND LEFT(VOUCHERNO,3)='" & BRANCHCODE & "' and len(voucherno)=12 and autogen>0", conn, adOpenDynamic, adLockOptimistic
If IsNull(rs_tmp12(0)) Then
STR_PVNO = STR_PVNO & Format(1, "000")
Else
STR_PVNO = STR_PVNO & Format(Val(rs_tmp12(0)) + 1, "000")
End If
VNO = STR_PVNO
End Sub