Function BrojDokumenta(Pref As String) Dim Db As Database Dim SQL As String Dim Rs As Recordset Dim i As Integer Set Db = CurrentDb SQL = "SELECT Max(Right(BrojDok,4)) FROM tblDokumenti" Set Rs = Db.OpenRecordset(SQL) If Format$(Rs.Fields(0)) <> "" Then i = Val(Rs.Fields(0)) End If i = i + 1 BrojDokumenta = Pref & Format(i, "0000") Rs.Close Set Db = Nothing End Function