Expression

J

Jason

I am looking to create an expression for a table that will
automatically generate a number. I require the format to
be in YYMM### format. I was able to establish both the
year and month portion but am having difficulty with the
numerical portion. The ### will begin at 001 and increase
by one with each new record. The ### will need to reset
to 001 at the beginning of each month. All help will be
appreciated.
 
W

Wayne Morgan

Assuming the table to be Table1 and the field to be Field1, a user defined
function such as this one should do it.

Public Function CodeNumber () As String
Dim intNumberToIncrement As Integer
intNumberToIncrement = Nz(DMax("CInt(Right([Field1],3))", "Table1",
"Left([Field1],4)='" & Format(Date, "yymm") & "'"), 0) +1

CodeNumber = Format(Date, "yymm") & Format(intNumberToIncrement, "000")
End Function

There is no check here to see if you exceed 999. You would want to add that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top