Z
Zanstemic
I'm having difficulty getting the following code to run. AutoCaseNumber is
the Control that has the value I need to save. It increments correctly when
opening however this is a multi user environment so if two forms open at the
same time, the numbers are the same. I'm trying to get AutoCaseNumber to add
one if the number already exists when saving.
The error is "validation rule violation"
If I setup a test where the number exists it does not seem to do the
incrementation.
Private Sub Save_Data_Click()
Dim AutoNumber As Long
Dim jetSQL
AutoNumber = Me!AutoCaseNumber
' pick a number to start at
Do While True
jetSQL = "INSERT INTO Attendees ([Date Received],CPSAutoNumber,
CaseNumber) VALUES (Forms![Create_Claim]![Registration Date],
Forms![Create_Claim]![txtRegistration Case Number],
Forms![Create_Claim]![AutoCaseNumber]);"
' db.Execute jetSQL, dbFailOnError
DoCmd.RunSQL jetSQL
If Err.Number <> 0 Then
' insert failed, someone else must have grabbed the
' same number just before us
AutoNumber = AutoNumber + 1
Me![AutoCaseNumber] = AutoNumber
Else
' okay it worked, this number now belongs to us
Exit Do
End If
Loop
' return myNumber to the calling procedure
End Sub
the Control that has the value I need to save. It increments correctly when
opening however this is a multi user environment so if two forms open at the
same time, the numbers are the same. I'm trying to get AutoCaseNumber to add
one if the number already exists when saving.
The error is "validation rule violation"
If I setup a test where the number exists it does not seem to do the
incrementation.
Private Sub Save_Data_Click()
Dim AutoNumber As Long
Dim jetSQL
AutoNumber = Me!AutoCaseNumber
' pick a number to start at
Do While True
jetSQL = "INSERT INTO Attendees ([Date Received],CPSAutoNumber,
CaseNumber) VALUES (Forms![Create_Claim]![Registration Date],
Forms![Create_Claim]![txtRegistration Case Number],
Forms![Create_Claim]![AutoCaseNumber]);"
' db.Execute jetSQL, dbFailOnError
DoCmd.RunSQL jetSQL
If Err.Number <> 0 Then
' insert failed, someone else must have grabbed the
' same number just before us
AutoNumber = AutoNumber + 1
Me![AutoCaseNumber] = AutoNumber
Else
' okay it worked, this number now belongs to us
Exit Do
End If
Loop
' return myNumber to the calling procedure
End Sub