For what it's worth, I would recommend that you keep the sequence number you derive in a separate numeric field, something like this:
CasePK CaseDate CaseMonthSeq
------ ---------- ------------
101 2013-10-01 1
That way you can streamline the process to derive new sequence numbers, and you can easily build the "CaseID" string from its constituent parts. (That is, it's always easier to glue strings together than it is to split them apart.)
The following test code illustrates how you could derive the sequence number when you insert the record into the table. Because the derivation is done inside the INSERT statement it should be done within an implicit transaction and therefore be suitable for a multi-user environment
Sub CaseSeqTest()
Dim cdb As DAO.Database, SQL As String
Dim dtCaseDate As Date
dtCaseDate = DateSerial(2013, 10, 3) ' sample date for testing
Set cdb = CurrentDb
SQL = _
"INSERT INTO Cases (" & _
"CaseDate, " & _
"CaseMonthSeq " & _
") VALUES (" & _
"#" & Format(dtCaseDate, "yyyy-mm-dd") & "#, " & _
"Nz(DMax(""CaseMonthSeq"", ""Cases"", ""Format(CaseDate, """"yymm"""") = """"" & Format(dtCaseDate, "yymm") & """""""), 0) + 1 " & _
")"
Debug.Print SQL
cdb.Execute SQL, dbFailOnError
Set cdb = Nothing
End Sub
The Debug.Print
statement simply prints the SQL command to be executed, in this case...
INSERT INTO Cases (CaseDate, CaseMonthSeq ) VALUES (#2013-10-03#, Nz(DMax("CaseMonthSeq", "Cases", "Format(CaseDate, ""yymm"") = ""1310"""), 0) + 1 )
...and the record is inserted into the table as follows:
CasePK CaseDate CaseMonthSeq
------ ---------- ------------
101 2013-10-01 1
102 2013-10-03 2
If you want to display the CaseID then you can always piece it together "on the fly", like this...
SELECT
CasePK,
CaseDate,
"CEF-" & Format(CaseDate, "yymm") & "-" & CaseMonthSeq AS CaseID
FROM Cases
...returning
CasePK CaseDate CaseID
------ ---------- ----------
101 2013-10-01 CEF-1310-1
102 2013-10-03 CEF-1310-2
...or, since you are using Access 2010 (or later) you could alter the [Cases] table to create a [CaseID] as a Calculated field using the expression
"CEF-" & Right(Year([CaseDate]),2) & IIf(Month([CaseDate])>9,"","0") & Month([CaseDate]) & "-" & [CaseMonthSeq]
so you could just retrieve [CaseID] directly and wouldn't keep having to re-create the logic to assemble the CaseID every time you wanted to use it in a query or report.