If IsNull(Me.txtInqIDNo) Then [COLOR=green]'Check for Existing Inquiry ID No on current form
'if inquiry ID does not exist on form then execute the following [/color]
Dim strFY, strSer, strInq As String [COLOR=green]'strings that piece the order number together[/color]
[COLOR=green]'Assign strFY the last two digits of current fiscal year.
'"Me.txtDate" is the text box that holds the current date, text box disabled and locked
'Check for current month. If on or after October, use the following year for fiscal year
'Otherwise, use current year for fiscal year (Fiscal Year Example: Oct 04 - Sep 05)[/color]
If Month(Me.txtDate) >= 10 Then
strFY = Right$((Year(Me.txtDate) + 1), 2)
Else
strFY = Right$(Year(Me.txtDate), 2)
End If
[COLOR=green]'Assign the next available serial number to strSer
'Check to see if there are any entries on table. If table is empty strSer = 000[/color]
If IsNull(DLookup("[fldInqIDNo]", "[tblInq]")) Then
strSer = "000"
Else
[COLOR=green]'Check to see if there are any entries on table under current fiscal year. If no
'records exist under current fiscal year, strSer = 000. If records do exist under current
'fiscal year, use ELookUp, to sort the existing records under current fiscal year in
'descending order and select the top record. Assign strSer the last three digits of top
'record.[/color]
If IsNull(DLookup("[fldInqIDNo]", "[tblInq]", "Mid$([fldInqIDNo], 5, 2) = '" & strFY & "'")) Then
strSer = "000"
Else
strSer = Right$(ELookup("[fldInqIDNo]", "tblInq", "Mid$([fldInqIDNo], 5, 2) = '" & strFY & "'", "fldInqIDNo DESC"), 3)
End If
End If
[COLOR=green]'Add 1 to strSer to assign strSer the next available number. Example: strSer=002, add 1,
'strSer = 003. After adding, strSer looses the leading zeros. If strSer<10, add two leading zeros
'to strSer. If str between 10 and 99 add one leading zero to strSer. Otherwise, leave strSer alone[/color]
strSer = strSer + 1
If strSer < 10 Then strSer = "00" & strSer
If strSer >= 10 And strSer < 100 Then strSer = "0" & strSer
[COLOR=green]'Assign strInq the next available inquiry number by piece-ing "INQ-", strFY, and strSer
'together and assing txtInqIDNo the result (strInq).[/color]
strInq = "INQ-" & strFY & strSer
Me.txtInqIDNo = strInq
Else
[COLOR=green]'if Inquiry ID does exist on form, do nothing [/color]
End If