Multiuser Custom Counter

P

PainInMyAccess

I am trying to create a multiuser custom counter to create an automated
tracking number on a form.
This is the code that we found:

Option Compare Database
Option Explicit

Function Next_Custom_Counter()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'For this code to work, it is required that you reference the:
' Microsoft ActiveX Data Objects 2.x Library
'To reference this library, go to the Tools menu, click
'References, and select the library from the list of available
'references (version 2.1 or higher).
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error GoTo Next_Custom_Counter_Err

Dim rs As ADODB.Recordset
Dim NextCounter As Long

Set rs = New ADODB.Recordset

'Open the ADO recordset.
rs.Open "CounterTable", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

'Get the next counter.
NextCounter = rs!NextAvailableCounter

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Open table and get the current value of NextAvailableNumber,
'increment the value by 10, and save the value back into the table
'
'The next line can be changed to conform to your custom counter
'preferences. This example increments the value by 10 each time.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rs!NextAvailableCounter = NextCounter + 10
NextCounter = rs!NextAvailableCounter
rs.Update

MsgBox "Next available counter value is " & Str(NextCounter)

rs.Close

Set rs = Nothing

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

The instructions then told me to place this code behind a command button.
=Next_Custom_Counter()

Error received:
Complie Error:
Expected: line number or label or statement or end of statement

What does this mean? Sorry, I know nothing about VBA and hoping someone can
help me out!

Thanks!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top