ник: ДрЮня
fфункци возвращает номер заказа в формате "номер года" / "номер заказа" - "07/01"
Public Function get_OrderNumber() As String
Dim sSQL As String, rs As ADODB.Recordset, s As String, b As Byte
On Error GoTo L_Err
get_OrderNumber = ""
Set rs = New ADODB.Recordset
sSQL = "SELECT Max(tblOrder.NumberOrder) AS MaxNum FROM tblOrder"
rs.Open sSQL, cnn
If rs.EOF Then
s = Format(Now(), "yy") & "/01_1"
Else
If Format(Now(), "yy") = Left(rs("MaxNum"), 2) Then
b = InStr(rs("MaxNum"), "_")
If b Then
s = Mid(rs("MaxNum"), 1, b) & Val(Right(rs("MaxNum"), 1)) + 1
Else
s = Val(Mid(rs("MaxNum"), 4)) + 1
s = IIf(Len(s) = 1, "0" & s, s)
s = Format(Now(), "yy") & "/" & s
End If
Else
s = Format(Now(), "yy") & "/01_1"
End If
End If
get_OrderNumber = s
L_Exit: Set rs = Nothing: Exit Function
L_Err: MsgBox Err.Description & " (" & Err.Number & ")", vbExclamation, "get_OrderNumber": GoTo L_Exit
End Function