A
a24t42
I am having problems getting a custom counter for multi user to work.
I am trying to follow Microsoft's article #210194 - How to create a
Mulituser custom counter but am not having any luck.
Here is what I have - A table called CounterTable with one field -
NextAvailableCounter. This is the primary field, long number.
A table called frm3PHPad that has a field called ID - Primary key,
long number.
For the form, I have the following code set on BeforeUpdate
------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)
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 1, and save the value back into the Table
'=================================================================
Set MyDB = CurrentDb
Set MyTable = MyDB.OpenRecordset("CounterTable")
MyTable.Edit
NextCounter = MyTable("NextAvailableCounter")
'=================================================================
'The next line can be changed to conform to your custom counter
'preferences. This example increments the value by 1 each time.
'=================================================================
MyTable("NextAvailableCounter") = NextCounter + 1
MyTable.Update
Next_Custom_Counter = NextCounter
Forms!frm3PHPad![ID] = 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
End Function
What I am trying to do is get the field [ID] to act as the counter,
for which the number is looked up in the table CustomTable and stored
in the [ID] field. My knowledge of VBA is minimal.
I hope that makes sense. Any help would be appreciated.
I am trying to follow Microsoft's article #210194 - How to create a
Mulituser custom counter but am not having any luck.
Here is what I have - A table called CounterTable with one field -
NextAvailableCounter. This is the primary field, long number.
A table called frm3PHPad that has a field called ID - Primary key,
long number.
For the form, I have the following code set on BeforeUpdate
------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)
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 1, and save the value back into the Table
'=================================================================
Set MyDB = CurrentDb
Set MyTable = MyDB.OpenRecordset("CounterTable")
MyTable.Edit
NextCounter = MyTable("NextAvailableCounter")
'=================================================================
'The next line can be changed to conform to your custom counter
'preferences. This example increments the value by 1 each time.
'=================================================================
MyTable("NextAvailableCounter") = NextCounter + 1
MyTable.Update
Next_Custom_Counter = NextCounter
Forms!frm3PHPad![ID] = 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
End Function
What I am trying to do is get the field [ID] to act as the counter,
for which the number is looked up in the table CustomTable and stored
in the [ID] field. My knowledge of VBA is minimal.
I hope that makes sense. Any help would be appreciated.