Thanks in advance to anyone who can be of assistance ...
I am trying to build on my existing code and still coming up with problems.
I have a field (i.e., trackingNo) which is formatted as follows: FY03 (the two digits after FY represents the fiscal year) and is auto-generated by the number of records (based on the trackingNo) for that FY (found in the table).
When the user clicks the "New" button, the function GenerateCY is ran. If there are existing records for that FY (i.e., FY03-038), then the next trackingNo will be incremented by 1 (i.e., FY03-039). If there are no records, then it is a start of a new FY (i.e., FY04), then the tracking no will start back at 1 and then increment by 1 for each new record in that FY. The new trackingNo will be FY04-001.
My thought process is to include a like clause in my sql statement to find the existing FYs (i.e., where TrackingNo), but I nothing that I write seems to work.
My GenerateFY code is as follows and generates when the user clicks on the new button:
I am trying to build on my existing code and still coming up with problems.
I have a field (i.e., trackingNo) which is formatted as follows: FY03 (the two digits after FY represents the fiscal year) and is auto-generated by the number of records (based on the trackingNo) for that FY (found in the table).
When the user clicks the "New" button, the function GenerateCY is ran. If there are existing records for that FY (i.e., FY03-038), then the next trackingNo will be incremented by 1 (i.e., FY03-039). If there are no records, then it is a start of a new FY (i.e., FY04), then the tracking no will start back at 1 and then increment by 1 for each new record in that FY. The new trackingNo will be FY04-001.
My thought process is to include a like clause in my sql statement to find the existing FYs (i.e., where TrackingNo), but I nothing that I write seems to work.
My GenerateFY code is as follows and generates when the user clicks on the new button:
Code:
Private Function GenerateFY()
Dim sSql As String
Dim rs As DAO.Recordset
Dim db As Database
Dim iCount As Integer
Dim sName As String
Dim gFiscalYear As Integer 'Get Fiscal Year
Dim cFiscalYear As Integer 'Get Calendar Year
Dim dte As Date 'Current Date
Dim iFY As Integer
'Get Calendar Year
cFiscalYear = Year(Date)
'System's Date Determine's the Fiscal Year (when user clicks on btnNew)
dte = Date
If (Month(dte) >= 10) Then
gFiscalYear = Year(dte) + 1
Else
gFiscalYear = Year(dte)
End If
'Format: FYxx
iFY = Right(gFiscalYear, 2)
sSql = "Select * tblConsultants" & _
sSql = sSql & "WHERE trackingNo Like 'FY' & ify & '*';"
Set db = CurrentDb()
Set rs = db.OpenRecordset(sSql)
If rs.RecordCount = 0 Then 'New FY
iCount = 1
sName = "FY" & Right(gFiscalYear, 2) & "-" & Format(iCount, "000")
Else 'Existing FY
iCount = rs.RecordCount + 1
sName = "FY" & Right(gFiscalYear, 2) & "-" & Format(iCount, "000")
End If
Me.trackingNo = sName
rs.Close
End Function