Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[COLOR=green]'Incremented Number field NOT using AutoNumber
'Tek-Tips Forum 5/3/2001
' from GHubbell
'Run a table called tblDocType. Includes fields called
'RefType: AutoNumber Description: Text Counter: Number UseCounter: True/False
'(Set "True" for form required)
'On Forms ADDNEWRECORD procedure, add this code
'DoCmd.GoToRecord,,acNewRec
'Me![Name of Field] = NextNumber(1) 'where 1 is the doctype number for this type of document
[/color]
Public Function NextNumber(RefType As Variant) As Variant
On Error GoTo ErrNN
Dim SQL1 As String
Dim Rs As Recordset
Dim DB As Database
Set DB = CurrentDb()
SQL1 = "SELECT tblDocType.* FROM tblDocType WHERE "
SQL1 = SQL1 & "(((tblDocType.RefType)= " & RefType & ") AND "
SQL1 = SQL1 & "((tblDocType.UseCounter)=True))"
Set Rs = DB.OpenRecordset(SQL1, dbOpenDynaset)
If Rs.RecordCount = 0 Then
Rs.Close
GoTo ErrNN
End If
NextNumber = Rs!Counter + 1
Rs.Edit
Rs!Counter = NextNumber
Rs.Update
Rs.Close
ExitNN:
Exit Function
ErrNN:
MsgBox Err.Number & " " & Err.Description, vbInformation, "Next Document Number Generation Error!"
Resume ExitNN
End Function