Z
zat
I am trying to do an auto correspondence number based on the current year and
have the counter start at 001 so the first correspondence number would be
2006-001 and the next record number would be 2006-002. In 2007 it would
start over with 2007-001. This numbering system would be activated when the
user selects a button (Command33). The table name is tblSyscounters with
fields: Pvar (unique key), YearPart (Current year), Countr (squential counter)
The following code is giving me a User defined-type not defined error that
points to Dim rs As DAO.Recordset. Does anyone have a clue what I'm doing
wrong?
Public Function GetNextNumber() As String
Dim rs As DAO.Recordset
Dim Year As Integer
Dim CompareYear As Long
Dim CurCount As Long
Set rs = db.OpenRecordset("tblSyscounters", dbOpenDynaset)
CompareYear = DatePart("yyyy", Date)
With rs
FindFirst "Key = 'Pvar'"
If !YearPart <> CompareYear Then
!Countr = 0
!YearPart = CompareYear
End If
!Countr = !Countr + 1
Update
Year = !YearPart - 2000
CurCount = !Countr
Close
End With
GoTo XIT
XIT:
GetNextNumber = "V" & Right$("00" & Year, 2) & "-" & Right$("00000" &
CurCount, 6)
End Function
The Event procedure for the button is:
Private Sub Command33_Click()
ingOutNum = GetNextNumber()
End Sub
have the counter start at 001 so the first correspondence number would be
2006-001 and the next record number would be 2006-002. In 2007 it would
start over with 2007-001. This numbering system would be activated when the
user selects a button (Command33). The table name is tblSyscounters with
fields: Pvar (unique key), YearPart (Current year), Countr (squential counter)
The following code is giving me a User defined-type not defined error that
points to Dim rs As DAO.Recordset. Does anyone have a clue what I'm doing
wrong?
Public Function GetNextNumber() As String
Dim rs As DAO.Recordset
Dim Year As Integer
Dim CompareYear As Long
Dim CurCount As Long
Set rs = db.OpenRecordset("tblSyscounters", dbOpenDynaset)
CompareYear = DatePart("yyyy", Date)
With rs
FindFirst "Key = 'Pvar'"
If !YearPart <> CompareYear Then
!Countr = 0
!YearPart = CompareYear
End If
!Countr = !Countr + 1
Update
Year = !YearPart - 2000
CurCount = !Countr
Close
End With
GoTo XIT
XIT:
GetNextNumber = "V" & Right$("00" & Year, 2) & "-" & Right$("00000" &
CurCount, 6)
End Function
The Event procedure for the button is:
Private Sub Command33_Click()
ingOutNum = GetNextNumber()
End Sub