Hi. I am trying to create a primary key to replace "autonumber". Ideally, it will still auto-increment:
GBQ04-001
GBQ04-002
GBQ04-003
GBQ is an identifier
04 is the year
001 is the increment
The form has a "Date Entered" field.
For the first record of any new year, the year should change accordingly and the incrementing number will start at 001 again. The identifier will remain constant.
I will need to enter records from 2002 to present. Thus when i start entering the final data, i will need to be able to type into the field with the Primary Key until i reach the present. From then on, it should be fully automated.
I've tried Help in Access and also tried searching the archives here, but end up scratching my head. Can someone help or guide me? I'm keen to learn and would greatly appreciate any help especially with a what/where/how/why I put the solution.
Should this be created in a table instead of a form?
I've tried this in a form:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me!GBQQuoteNo = Nz(DMax("[GBQQuoteNo]", "[tblGBQQuotes]"), 0) + 1
End Sub
- it's not working.
I think my primary key should be created in a table instead.
Please help.
GBQ04-001
GBQ04-002
GBQ04-003
GBQ is an identifier
04 is the year
001 is the increment
The form has a "Date Entered" field.
For the first record of any new year, the year should change accordingly and the incrementing number will start at 001 again. The identifier will remain constant.
I will need to enter records from 2002 to present. Thus when i start entering the final data, i will need to be able to type into the field with the Primary Key until i reach the present. From then on, it should be fully automated.
I've tried Help in Access and also tried searching the archives here, but end up scratching my head. Can someone help or guide me? I'm keen to learn and would greatly appreciate any help especially with a what/where/how/why I put the solution.
Should this be created in a table instead of a form?
I've tried this in a form:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me!GBQQuoteNo = Nz(DMax("[GBQQuoteNo]", "[tblGBQQuotes]"), 0) + 1
End Sub
- it's not working.
I think my primary key should be created in a table instead.
Please help.
Last edited: