Article ID: 140908
Article Last Modified on 1/19/2007
Function Next_Custom_Counter ()
On Error GoTo Next_Custom_Counter_Err
Dim MyDB As Database
Dim MyTable As Recordset
Dim NextCounter As Long
'=================================================================
'Open table and get the current value of "Next Available Number,"
'increment the value by 10, and save the value back into the table
'=================================================================
Set MyDB = CurrentDb
Set MyTable = MyDB.OpenRecordset("Counter Table")
MyTable.Edit
NextCounter = MyTable("Next Available Counter")
'=================================================================
'The next line can be changed to conform to your custom counter
'preferences. This example increments the value by 10 each time.
'=================================================================
MyTable("Next Available Counter") = NextCounter + 10
MyTable.Update
MsgBox "Next available counter value is " & Str$(NextCounter)
Next_Custom_Counter = NextCounter
Exit Function
'================================================================
'The following error routine should be replaced with a custom
'error routine. This example only resumes execution when an error
'occurs. If a record locking error occurs this is fine; however,
'any non-record locking error will result in an infinite loop.
'================================================================
Next_Custom_Counter_Err:
Msgbox "Error " & Err & ": " & Error$
If Err <> 0 Then Resume
End
End Function
=Next_Custom_Counter()
Keywords: kbhowto kbprogramming kbusage KB140908