What happens in 2010? You not only have a Y2K problem, you want to be beat
up in 6 years. I've changed you request to a format of 2004036-01. Feed this
your field name and table name in quoted and you'll get what you need. Put
the code in a standard module. Set the textbox's DefaultValue to: -
DateIncrement("YourFieldName", "YourTableName")
Public Function DateIncrement(strField As String, strTable As String) As
String
'********************************************************************
' Name: DateIncrement
'
' Inputs: strField As String
' strTable As String
'
' Returns: String
'
' Author: Arvin Meyer
' Date: February 05, 2004
' Comment: Increments last 2 digits based on date (Year and DayNumber)
' Format is 2004036-01
'
'********************************************************************
On Error GoTo Err_DateIncrement
Static intNum As Integer
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("Select " & strField & " From " & strTable & "
Order by " & strField & ";")
If Not rst.EOF Then
rst.MoveLast
If Left(rst.Fields(strField), 7) = Year(Date) & Format(DatePart("y",
Date), "000") Then
intNum = Val(Mid(rst.Fields(strField), 9)) + 1
Else
intNum = 1
End If
Else
intNum = 1
End If
DateIncrement = Year(Date) & Format(DatePart("y", Date), "000") & "-" &
Format(intNum, "00")
Exit_DateIncrement:
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Function
Err_DateIncrement:
MsgBox Err.Description
Resume Exit_DateIncrement
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access