The 99 Vs. 100 issue
If you use
Code:
If OldSuffix < 100 Then
NewSuffix = OldSuffix + 1
Then, when OldSuffix = 99, the statement will evaluate to TRUE and
NewSuffix will be computed as 99 + 1 = 100 and that is not
a legal value for the suffix.
Conversly, If you use
Code:
If OldSuffix < 99 Then
NewSuffix = OldSuffix + 1
when OldSuffix = 98 then the statement is TRUE and NewSuffix is computed as 98 + 1 = 99 so 99 does indeed get used.
when OldSuffix = 99 then the code will pick up "NextClosedSuffix"
as its value and will not increment to 100.
Quotes and Brackets
You had constructs of the form
Code:
If Forms![Induct Gear]![Sub Shop] = "4" Then
LastEntryNumber = DMax("Entry Number", "In Maintenance", "Sub Shop = 4")
[blue]etc.[/blue]
That is, you were testing the value found in
Forms![Induct Gear]![Sub Shop] and then creating a DMax
call incorporating the same ... now hard-coded, value
that you found. I just simplified it to
Code:
LastEntryNumber = DMax("Entry Number", "In Maintenance", _
"[Sub Shop] = '" & Forms![Induct Gear]![Sub Shop] & "'")
which, after the value in Forms![Induct Gear]![Sub Shop] is resolved, would reduce to
Code:
LastEntryNumber = DMax("Entry Number", "In Maintenance", _
"[Sub Shop] = '4'")
Given the spaces in the names, "Entry Number", "In Maintenance" and "Sub Shop", you should probably have
brackets around all of them as in
Code:
LastEntryNumber = DMax("[red][[/red]Entry Number[red]][/red]", "[red][[/red]In Maintenance[red]][/red]", _
"[red][[/red]Sub Shop[red]][/red] = '" & Forms![Induct Gear]![Sub Shop] & "'")
That applies to all your DMin, DMax and DLookup calls.
NULLs
The functions DMax, DMin and DLookup will return NULL if the
underlying SQL returns no records. The variables to which
you are assigning the retrieved values are declared as Strings and a string cannot accept NULL as a value. Change
the type to Variant and, after issuing the DMin, DMax or DLookup call
test for a NULL in the returned value. Since I don't know
the structure of these tables I'm not really sure about
what action should be taken when a NULL is returned.
Different 'Next' Values
Since those were not typos then you can just expand the
SELECT CASE
Code:
Select Case OldPrefix
Case "HDA", "HDB", "HDC", "HDY", "HDZ"
NewPrefix = OldPrefix
Case "HDE"
NewPrefix = "HDD"
Case "HDX"
NewPrefix = "HDF"
Case Else
NewPrefix = "HD" & Chr(Asc(Right(OldPrefix, 1)) + 1)
End Select
and whatever other exceptions you have.
Type Mismatch
Not really sure about that one. The message is usually
associated with attempting a comparison between a field
and a value where the types don't match. Check the
data types for [Sub Shop] and [Status] in the table to
be sure that they are both Text fields.