Gentlemen,
I am new to the access application development, with the help of my friend I have written code to generate custom ID numbers.
what is does:
1.creates numbers upon creating new record.
2.gets the year from the date(field) of event and combines with this auto number and stored in Field name "OCCID" in "EventTbl" table.
Question(HELP):
If the previous year event is recorded in current year example current year 2011 and event date year is 2010, the custom number stored in field "OCCID" is not getting 2010XXXX last number but stores 2011XXXX.
example: the last number in 2010 is 20100096 and for the year 2011 it is 20110007. If new record is created for the year 2010, the next new number is 20110008 instead of 20100097.
The code is mentioned below.
I am new to the access application development, with the help of my friend I have written code to generate custom ID numbers.
what is does:
1.creates numbers upon creating new record.
2.gets the year from the date(field) of event and combines with this auto number and stored in Field name "OCCID" in "EventTbl" table.
Question(HELP):
If the previous year event is recorded in current year example current year 2011 and event date year is 2010, the custom number stored in field "OCCID" is not getting 2010XXXX last number but stores 2011XXXX.
example: the last number in 2010 is 20100096 and for the year 2011 it is 20110007. If new record is created for the year 2010, the next new number is 20110008 instead of 20100097.
The code is mentioned below.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me!OCCID) Then
Dim dbs As Database
Set dbs = CurrentDb
Dim rs As DAO.Recordset
Set rs = dbs.OpenRecordset("select max(CInt(Mid([OCCID], 5))) from EventTbl where Year([Date]) =" & Year(Me.[Date]))
If IsNull(rs(0)) = True Then
Me.OCCID = Year(Me.[Date]) & "" & Format(1, "0000")
Else
Me.OCCID = Year(Me.[Date]) & "" & Format(rs(0) + 1, "0000")
End If
'Me.OCCID = Nz(DMax("[OCCID]", "EventTbl", "Year([OccDate])=" & Year(Me.[OccDate])), 0) + 1
End If
Thanks in advance for who ever is putting the efforts to response or reply.
Regards,
Bari
End Sub
Comment