pod is going in the right direction, so I will just expand a bit on what he has said.
I would create only 2 fields, one to store the date and one to store the ID of the record, and let the primary key be the combination of the two. If you truly need to display the combined ID I would then make a calculated field in the query or the form/report.
In your table, have fields Date_Created and lng_DailyID. In your form, bind these to textboxes txt_DateCreated and txt_DailyID. Ensure that both textboxes are locked (And possibly disabled).
Make the Default Value for the txt_DateCreated be "=Date()".
Select your FORM properties, go the event tab, and select the event Before_Update. In the dropdown, select [Event Procedure] and then click the ... on the right hand side.
Now this will take you the VBA window, and place the cursor inside a piece of text like so:
- Private Sub Form_BeforeUpdate(Cancel as True)
-
-
End Sub
Modify the code to look like so:
- Private Sub Form_BeforeUpdate(Cancel as True)
-
'Only apply to new records
-
If Me.NewRecord Then
-
me.txt_DailyID=nz(Dmax("lng_DailyID","[InsertTableNameHere]","DateCreated=#" & me.tb_DateCreated & "#"),0)+1
-
End If
-
End Sub
The Dmax will find the max used ID for that day. In case its the first record of the day it will return null, which is why its encapsualted in a NZ(Dmax,0) which will safely convert the Null to 0, and finally it is incremented by one.
If you need to display your special ID, simply add to your query:
- Serial: Format([DateCreated],"yymmdd") + lng_DailyID