DarrenBoyer
IS-IT--Management
I'm probably going to cringe when I see the solution to this but I need to ask for help anyway.
I'm very new to coding but having a blast learning. Lately I have been consumed trying to implement MichaelRed's FAQ 700-184.
I'm using Access 2003 but thought I liked what I read enough to want to try and figure out this approach even thought it was DAO.
I beleive I've modified the code properly but now am having a real issue trying to have the CustomerID value updated when a user try's to start a new record. (The table has 5300 existing Customer's imported with a Customer ID.) I thought the BeforeUpdate Event was the right approach but when that didn't work I tried other events until I came to the conclusion I don't know how to get the job done right now.
Here's my modification which compiles fine:
Public Function CustomerID_Current()
On Error GoTo Custom_Counter_Err
Dim NextAvailableCustomerID As Long
Dim db As DAO.Database
Dim BaseData As Recordset
Dim tblCounterTable As Recordset
Dim qSelCustomerIDMax As Recordset
Const RiErr = 3000
Const LockErr = 3260
Const InUseErr = 3262
Const NumReTries = 20#
'Variables for the Retry Counts
Dim NumLocks As Integer
Dim lngX As Long
'Variables Used in the Code
Dim NextAvailableCounter As Long
Dim lngOldCustomerID As Long
Dim lngNewCustomerID As Long
Dim lngBigCustomerID As Long
Set db = CurrentDb()
Set BaseData = db.OpenRecordset("Customers")
Set tblCounterTable = db.OpenRecordset("tblCounterTable", dbDenyRead)
lngBigCustomerID = tblCounterTable!NextAvailableCounter 'C
'Increment the ID
lngBigCustomerID = lngBigCustomerID + 10
'Update the ID Value
With Custom_Counter
.Edit
!NextAvailableCounter = lngBigCustomerID
.Update
End With
MsgBox "Next Available Counter is " & Str(NextAvailableCounter)
lngNewCustomerID = lngBigCustomerID
NormExit:
Set BaseData = Nothing
Set db = Nothing
Exit Function 'Return
Custom_Counter_Err:
'Check For the expected errors
If ((Err = InUseErr) Or (Err = LockErr) Or (Err = RiErr)) Then
'If one of the expected ones, increment the counter
NumLocks = NumLocks + 1
If (NumLocks < NumReTries) Then
For lngX = 1 To NumLocks ^ 2 * Int(Rnd * 20 + 5)
DoEvents
Next lngX
Resume Next
Else
End If
Else
MsgBox "Error" & Err.Number & ": " & Err.Description, _
vbOKOnly & vbCritical, "Get CustomerID"
GoTo NormExit
End If
End Function
I'm very new to coding but having a blast learning. Lately I have been consumed trying to implement MichaelRed's FAQ 700-184.
I'm using Access 2003 but thought I liked what I read enough to want to try and figure out this approach even thought it was DAO.
I beleive I've modified the code properly but now am having a real issue trying to have the CustomerID value updated when a user try's to start a new record. (The table has 5300 existing Customer's imported with a Customer ID.) I thought the BeforeUpdate Event was the right approach but when that didn't work I tried other events until I came to the conclusion I don't know how to get the job done right now.
Here's my modification which compiles fine:
Public Function CustomerID_Current()
On Error GoTo Custom_Counter_Err
Dim NextAvailableCustomerID As Long
Dim db As DAO.Database
Dim BaseData As Recordset
Dim tblCounterTable As Recordset
Dim qSelCustomerIDMax As Recordset
Const RiErr = 3000
Const LockErr = 3260
Const InUseErr = 3262
Const NumReTries = 20#
'Variables for the Retry Counts
Dim NumLocks As Integer
Dim lngX As Long
'Variables Used in the Code
Dim NextAvailableCounter As Long
Dim lngOldCustomerID As Long
Dim lngNewCustomerID As Long
Dim lngBigCustomerID As Long
Set db = CurrentDb()
Set BaseData = db.OpenRecordset("Customers")
Set tblCounterTable = db.OpenRecordset("tblCounterTable", dbDenyRead)
lngBigCustomerID = tblCounterTable!NextAvailableCounter 'C
'Increment the ID
lngBigCustomerID = lngBigCustomerID + 10
'Update the ID Value
With Custom_Counter
.Edit
!NextAvailableCounter = lngBigCustomerID
.Update
End With
MsgBox "Next Available Counter is " & Str(NextAvailableCounter)
lngNewCustomerID = lngBigCustomerID
NormExit:
Set BaseData = Nothing
Set db = Nothing
Exit Function 'Return
Custom_Counter_Err:
'Check For the expected errors
If ((Err = InUseErr) Or (Err = LockErr) Or (Err = RiErr)) Then
'If one of the expected ones, increment the counter
NumLocks = NumLocks + 1
If (NumLocks < NumReTries) Then
For lngX = 1 To NumLocks ^ 2 * Int(Rnd * 20 + 5)
DoEvents
Next lngX
Resume Next
Else
End If
Else
MsgBox "Error" & Err.Number & ": " & Err.Description, _
vbOKOnly & vbCritical, "Get CustomerID"
GoTo NormExit
End If
End Function