Hi
I have a form which has upto three users entering at the same time using Front Ends on their desktops linked to a back end on a server.
I have a field on the form which is updated using a Dmax piece of code. The number is unique. I am having a problem with the users being given the same number by the table and then getting a violation because of the duplication.
I have tried to enter a save record line straight after the Dmax code but this has not cured the problem.
Could someone look at the code posted below and give me some suggestions.
The code is quite long so I have highlighted the particular DMax line.
The users are activating the code at the same time.
Private Sub txtComments_LostFocus()
On Error GoTo Err_handler_lostfocus
retvalue = MsgBox("Do You Want To Add Another Sample To This Batch", vbYesNo)
If retvalue = vbNo Then
If Me.Our_Sample_Number = 0 Then
Me.Our_Sample_Number = Nz(DMax("[Our Sample Number]", "Sample Details"), 0) + 1
Me.Dirty = False
Me.CreatedBy = fOSUserName
Me.CreatedByDate = Date
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.txtComments.LimitToList = False
Me.frmAssistFMSampleEntrySubform.Requery
retvalue = MsgBox("Does The Sample Count Match To Data Collection Sheets?", vbYesNo)
If retvalue = vbNo Then
cmdCloseForm.SetFocus
Else
DoCmd.OpenReport "rptAssistFMLabSheet", acViewPreview
End If
Else
Me.Dirty = False
Me.CreatedBy = fOSUserName
Me.CreatedByDate = Date
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.txtComments.LimitToList = False
Me.frmAssistFMSampleEntrySubform.Requery
retvalue = MsgBox("Does The Sample Count Match To Data Collection Sheets?", vbYesNo)
If retvalue = vbNo Then
cmdCloseForm.SetFocus
Else
DoCmd.OpenReport "rptAssistFMLabSheet", acViewPreview
End If
End If
Else
If Me.Our_Sample_Number = 0 Then
Me.Our_Sample_Number = Nz(DMax("[Our Sample Number]", "Sample Details"), 0) + 1
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.txtComments.LimitToList = False
Me.CreatedBy = fOSUserName
Me.CreatedByDate = Date
Me.Dirty = False
DoCmd.GoToRecord , , acNewRec
Me.txtSeperator.Locked = False
Me.txtComments.Locked = False
Me.Check42.Locked = False
Me.Clients_Sample_Number.Locked = False
Me.Floor_Level.Locked = False
Me.Room_Location.Locked = False
Me.ItemLocation.Locked = False
Me.Item.Locked = False
Me.Component.Locked = False
Me.PrevSampleNo.Locked = False
Me.DrwgNo.Locked = False
Me.PhotoNo.Locked = False
Me.ProductType.Locked = False
Me.ExtentofDamage.Locked = False
Me.SurfaceTreatment.Locked = False
Me.Identified.Locked = False
Me.QuantityOfMaterial.Locked = False
Me.Action.Locked = False
Me.Access_Position.Locked = False
Me.OccupantNormal.Locked = False
Me.OccupantSecond.Locked = False
Me.LikeliLocation.Locked = False
Me.LikeliAccessibility.Locked = False
Me.LikeliQtyExtent.Locked = False
Me.HEFreqUse.Locked = False
Me.HEOccup.Locked = False
Me.HETimeInUse.Locked = False
Me.MaintenanceType.Locked = False
Me.MaintenanceFrequency.Locked = False
Me.Batch_Number = Forms![frmAssistFMBatchDetails]![Batch Number]
Me.txtSeperator.SetFocus
Else
Me.txtComments.LimitToList = False
Me.CreatedBy = fOSUserName
Me.CreatedByDate = Date
Me.Dirty = False
DoCmd.GoToRecord , , acNewRec
Me.txtSeperator.Locked = False
Me.txtComments.Locked = False
Me.Check42.Locked = False
Me.Clients_Sample_Number.Locked = False
Me.Floor_Level.Locked = False
Me.Room_Location.Locked = False
Me.ItemLocation.Locked = False
Me.Item.Locked = False
Me.Component.Locked = False
Me.PrevSampleNo.Locked = False
Me.DrwgNo.Locked = False
Me.PhotoNo.Locked = False
Me.ProductType.Locked = False
Me.ExtentofDamage.Locked = False
Me.SurfaceTreatment.Locked = False
Me.Identified.Locked = False
Me.QuantityOfMaterial.Locked = False
Me.Action.Locked = False
Me.Access_Position.Locked = False
Me.OccupantNormal.Locked = False
Me.OccupantSecond.Locked = False
Me.LikeliLocation.Locked = False
Me.LikeliAccessibility.Locked = False
Me.LikeliQtyExtent.Locked = False
Me.HEFreqUse.Locked = False
Me.HEOccup.Locked = False
Me.HETimeInUse.Locked = False
Me.MaintenanceType.Locked = False
Me.MaintenanceFrequency.Locked = False
Me.Batch_Number = Forms![frmAssistFMBatchDetails]![Batch Number]
Me.txtSeperator.SetFocus
End If
End If
Exit_handler_lostfocus:
Exit Sub
Err_handler_lostfocus:
MsgBox Err.description
Resume Exit_handler_lostfocus
End Sub
Many Thanks
Richard
I have a form which has upto three users entering at the same time using Front Ends on their desktops linked to a back end on a server.
I have a field on the form which is updated using a Dmax piece of code. The number is unique. I am having a problem with the users being given the same number by the table and then getting a violation because of the duplication.
I have tried to enter a save record line straight after the Dmax code but this has not cured the problem.
Could someone look at the code posted below and give me some suggestions.
The code is quite long so I have highlighted the particular DMax line.
The users are activating the code at the same time.
Private Sub txtComments_LostFocus()
On Error GoTo Err_handler_lostfocus
retvalue = MsgBox("Do You Want To Add Another Sample To This Batch", vbYesNo)
If retvalue = vbNo Then
If Me.Our_Sample_Number = 0 Then
Me.Our_Sample_Number = Nz(DMax("[Our Sample Number]", "Sample Details"), 0) + 1
Me.Dirty = False
Me.CreatedBy = fOSUserName
Me.CreatedByDate = Date
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.txtComments.LimitToList = False
Me.frmAssistFMSampleEntrySubform.Requery
retvalue = MsgBox("Does The Sample Count Match To Data Collection Sheets?", vbYesNo)
If retvalue = vbNo Then
cmdCloseForm.SetFocus
Else
DoCmd.OpenReport "rptAssistFMLabSheet", acViewPreview
End If
Else
Me.Dirty = False
Me.CreatedBy = fOSUserName
Me.CreatedByDate = Date
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.txtComments.LimitToList = False
Me.frmAssistFMSampleEntrySubform.Requery
retvalue = MsgBox("Does The Sample Count Match To Data Collection Sheets?", vbYesNo)
If retvalue = vbNo Then
cmdCloseForm.SetFocus
Else
DoCmd.OpenReport "rptAssistFMLabSheet", acViewPreview
End If
End If
Else
If Me.Our_Sample_Number = 0 Then
Me.Our_Sample_Number = Nz(DMax("[Our Sample Number]", "Sample Details"), 0) + 1
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.txtComments.LimitToList = False
Me.CreatedBy = fOSUserName
Me.CreatedByDate = Date
Me.Dirty = False
DoCmd.GoToRecord , , acNewRec
Me.txtSeperator.Locked = False
Me.txtComments.Locked = False
Me.Check42.Locked = False
Me.Clients_Sample_Number.Locked = False
Me.Floor_Level.Locked = False
Me.Room_Location.Locked = False
Me.ItemLocation.Locked = False
Me.Item.Locked = False
Me.Component.Locked = False
Me.PrevSampleNo.Locked = False
Me.DrwgNo.Locked = False
Me.PhotoNo.Locked = False
Me.ProductType.Locked = False
Me.ExtentofDamage.Locked = False
Me.SurfaceTreatment.Locked = False
Me.Identified.Locked = False
Me.QuantityOfMaterial.Locked = False
Me.Action.Locked = False
Me.Access_Position.Locked = False
Me.OccupantNormal.Locked = False
Me.OccupantSecond.Locked = False
Me.LikeliLocation.Locked = False
Me.LikeliAccessibility.Locked = False
Me.LikeliQtyExtent.Locked = False
Me.HEFreqUse.Locked = False
Me.HEOccup.Locked = False
Me.HETimeInUse.Locked = False
Me.MaintenanceType.Locked = False
Me.MaintenanceFrequency.Locked = False
Me.Batch_Number = Forms![frmAssistFMBatchDetails]![Batch Number]
Me.txtSeperator.SetFocus
Else
Me.txtComments.LimitToList = False
Me.CreatedBy = fOSUserName
Me.CreatedByDate = Date
Me.Dirty = False
DoCmd.GoToRecord , , acNewRec
Me.txtSeperator.Locked = False
Me.txtComments.Locked = False
Me.Check42.Locked = False
Me.Clients_Sample_Number.Locked = False
Me.Floor_Level.Locked = False
Me.Room_Location.Locked = False
Me.ItemLocation.Locked = False
Me.Item.Locked = False
Me.Component.Locked = False
Me.PrevSampleNo.Locked = False
Me.DrwgNo.Locked = False
Me.PhotoNo.Locked = False
Me.ProductType.Locked = False
Me.ExtentofDamage.Locked = False
Me.SurfaceTreatment.Locked = False
Me.Identified.Locked = False
Me.QuantityOfMaterial.Locked = False
Me.Action.Locked = False
Me.Access_Position.Locked = False
Me.OccupantNormal.Locked = False
Me.OccupantSecond.Locked = False
Me.LikeliLocation.Locked = False
Me.LikeliAccessibility.Locked = False
Me.LikeliQtyExtent.Locked = False
Me.HEFreqUse.Locked = False
Me.HEOccup.Locked = False
Me.HETimeInUse.Locked = False
Me.MaintenanceType.Locked = False
Me.MaintenanceFrequency.Locked = False
Me.Batch_Number = Forms![frmAssistFMBatchDetails]![Batch Number]
Me.txtSeperator.SetFocus
End If
End If
Exit_handler_lostfocus:
Exit Sub
Err_handler_lostfocus:
MsgBox Err.description
Resume Exit_handler_lostfocus
End Sub
Many Thanks
Richard