' Find max ID from the table
i = DMax("ID", "tbl_Mas_DocLog")
MsgBox "Max id=" & i
' Look for Doccode against that ID
a = DLookup("DocCode", "tbl_Mas_DocLog", "ID=" & i)
MsgBox "DocCode=" & a
'Find the Unique Code after "/"
j = Val(Mid(a, InStr(a, "/") + 1)) + 1
' Look for Staff Name corresponding to the Staff Number
b = DLookup("[Staff Name]", "tblstaff", "[Staff Number]=" & Right(Environ("username"), 6) & "")
' Find Initials using the below formula
initial = Left(b, 1) & Mid(b, InStr(1, b & " ", " ") + 1, 1)
' The Unique DocCode will be as below:
Ref = initial & Format(Date, "ddmmyy") & "/" & j
txtCode = Ref