Public Function NewNo() As Long
On Error GoTo NextNo_Err
Dim lngNextNo As Long
[COLOR=Green] 'Find highest No in the Skips Delivered table and add 1[/COLOR]
lngNextNo = Nz(DMax("[txtNo]", "Skips Delivered"), 0) + 1
[COLOR=Green] 'Assign function the value of the Next No[/COLOR]
NewNo = lngNextNo
[COLOR=Green]'Exit function now after successful incrementing or after error message[/COLOR]
Exit_NewNo:
Exit Function
[COLOR=Green]'If an error occurred, display a message, then go to Exit statement[/COLOR]
NextNo_Err:
MsgBox "Error " & Err & ": " & Error$
Resume Exit_NewNo
End Function