Hallo
I have a form which is used to create job sheets, where the control JobNumber is the primary key in tblnapswork
As more than one user can be entering at one time I need to prevent duplicate job numbers being given out by the system. I have a module which should trap the Error 3022 and effectively pause one of the users until the other user has finished running their bit of the code. My problem is that this does not appear to be working.
Below is a portion of the code for the Save button on the form and also the code within the Module.
Save Button Code:-
If Me.JobNumber = 0 Then
Me.inputdate.Value = Date
NextAssistFMJobNo
Me.CreatedByUser = fOSUserName
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
When the save button is clicked the second user gets a job number and then the error 3022 message appears stating that duplicate values will be created etc.
The debugger shows the code has fallen over at the Docmd.Domenuitem line.
This should have been handled by the module code below:-
On Error Resume Next
If Forms![frmnapswork]![txtUKASSelect] = -1 Then
Forms![frmnapswork]![JobNumber] = Nz(DMax("[UKASjobnumber]", "tblUkasjobnumbers"), 0) + 1
Forms![frmnapswork].Refresh
Else
Forms![frmnapswork]![JobNumber] = Nz(DMax("[NUjobnumber]", "tblNUjobnumbers"), 0) + 1
Forms![frmnapswork]!frmNUJobNumberssubform.Form!NUJobNumber = Forms![frmnapswork]!JobNumber
Forms![frmNUJobNumberssubform].Form.Dirty = False
Forms![frmnapswork].Refresh
End If
If Err = 3022 Then
Forms![frmnapswork]![JobNumber] = ""
Forms![frmnapswork].Refresh
NextAssistFMJobNo
End If
End Function
If anyone has any ideas/thoughts then they would be gratefully received.
Thanks
Richard Nuttall
I have a form which is used to create job sheets, where the control JobNumber is the primary key in tblnapswork
As more than one user can be entering at one time I need to prevent duplicate job numbers being given out by the system. I have a module which should trap the Error 3022 and effectively pause one of the users until the other user has finished running their bit of the code. My problem is that this does not appear to be working.
Below is a portion of the code for the Save button on the form and also the code within the Module.
Save Button Code:-
If Me.JobNumber = 0 Then
Me.inputdate.Value = Date
NextAssistFMJobNo
Me.CreatedByUser = fOSUserName
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
When the save button is clicked the second user gets a job number and then the error 3022 message appears stating that duplicate values will be created etc.
The debugger shows the code has fallen over at the Docmd.Domenuitem line.
This should have been handled by the module code below:-
On Error Resume Next
If Forms![frmnapswork]![txtUKASSelect] = -1 Then
Forms![frmnapswork]![JobNumber] = Nz(DMax("[UKASjobnumber]", "tblUkasjobnumbers"), 0) + 1
Forms![frmnapswork].Refresh
Else
Forms![frmnapswork]![JobNumber] = Nz(DMax("[NUjobnumber]", "tblNUjobnumbers"), 0) + 1
Forms![frmnapswork]!frmNUJobNumberssubform.Form!NUJobNumber = Forms![frmnapswork]!JobNumber
Forms![frmNUJobNumberssubform].Form.Dirty = False
Forms![frmnapswork].Refresh
End If
If Err = 3022 Then
Forms![frmnapswork]![JobNumber] = ""
Forms![frmnapswork].Refresh
NextAssistFMJobNo
End If
End Function
If anyone has any ideas/thoughts then they would be gratefully received.
Thanks
Richard Nuttall