I can't figure out why this isn't working. Within table PC_LOG, a text field is named [Request Number]. An example is FY14-099. What I'm trying to do is increase the numerial portion by 1. I first have to confirm I'm within the correct fiscal year, ie: FY14, then look for the MAX numeric part of [Request Number]. When I run the following code, it exits out of the sub when trying to do the msgbox rst.Fields(0)
Dim FiscalYear As Integer
Dim MaxRequestNumber As String
'Request Number is based on fiscal year, and a numeric count within that year
'Fiscal year is from July to June
'Establish correct year, and assign to variable FiscalYear
If DatePart("m", Date) > 6 Then
FiscalYear = Right(DatePart("yyyy", Date), 2) + 1
Else
FiscalYear = Right(DatePart("yyyy", Date), 2)
End If
'SELECT Max(Right([request number],3)) AS MaxNumber FROM PC_LOG WHERE (((PC_LOG.[Request Number]) Like "FY14*"))
strSQL = "SELECT Max(Right(PC_LOG.[Request Number],3)) AS MaxNumber FROM PC_LOG WHERE (((PC_LOG.[Request Number]) Like "
strSQL = strSQL & Chr(34) & "FY" & FiscalYear & "*" & Chr(34) & "))"
Set rst = New ADODB.Recordset
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
MsgBox rst.Fields(0)
rst.Close
Set rst = Nothing
I've confirmed the recordset only has 1 record. Thank you in advance!!