Okay I am trying this on my own, but struggling.
I added another Field called mo and in there I will store the month number.
March = 3.
If the current month and the mo do not match then I want the num to change
back to 01 and then I want the mo data to change to the current month number.
Below is my attempt. I am struggling with updating the mo data. Can you offer
some help?
Thank you
Public Function GetSeqNum() As String
Dim db As DAO.Database
Dim strSql As String
Dim strSql2 As String
Dim rs As DAO.Recordset
Dim strNum As String
Dim strMon As String
Dim intNum As Integer
Dim strRet As String
Dim strMonth As String
On Error GoTo seqnum_err
Set db = CurrentDb()
strSql = "Select num From tblSeqNum"
strSql2 = "Select mo From tblSeqNum"
Set rs = db.OpenRecordset(strSql)
strMon = DLookup("[mo]", "tblSeqNum")
strMonth = DatePart("m", Now)
strNum = rs(0)
If strMon <> strMonth Then
'If Day(Date) = 1 And strNum <> "01" Then 'if it's day 1 then reset the
number
strSql = "Update tblSeqNum set num = ""01"""
db.Execute strSql
strSql2 = "Update tblSeqNum set mo = strMonth"
db.Execute strSql2
GetSeqNum = "01"
Else
If Asc(strNum) = 48 Then 'because it's a string, we have to_
'increment then add the leading zero back in
intNum = CInt(strNum)
intNum = intNum + 1
If intNum <= 9 Then
strNum = "0" & CStr(intNum)
Else
strNum = CStr(intNum)
End If
Else ' it's 10 or greater
strNum = CStr(CInt(strNum) + 1)
End If
strSql = "Update tblSeqNum set num =""" & strNum & """"
db.Execute strSql
GetSeqNum = strNum
End If
ExitHere:
If Not rs Is Nothing Then
Set rs = Nothing
End If
If Not db Is Nothing Then
Set db = Nothing
End If
Exit Function
seqnum_err:
MsgBox "Error! " & Err.Description
GoTo ExitHere
End Function
dan said:
Sorry, please edit this line to include the extra check:
If Day(Date) = 1 And strNum <> "01" Then 'if it's day 1 then reset the
number, but only if it's the first time!
I forgot to check to se if the number had already been re-set.
I need to assign a sequential number to a serial number. The serial number
is
[quoted text clipped - 7 lines]