hi
i have designed a form that creates records in a table. As I don't want to have duplicate records, I have made 3 fields as primary key in that table. By pressing a button in the form, records are created in the table. When User wrongly clicks the button with the same data on the form, access shows a message that records could not be created and the form could not be closed. I have tried to solve the problem with showing a message box and not entering the sub, but it didn't raise the problem. How can I fix this problem?
This my code:
Private Sub cmdCreate_Click()
On Error GoTo aaa
bb:
For i = 0 To Me.SampleCounter + 1
Me.LayerSubform.Visible = True
LayerSubform.SetFocus
DoCmd.GoToRecord , , acNewRec
[LayerSubform]![ProjectCode] = ProjectCode
[LayerSubform]![ProjectName] = ProjectName
[LayerSubform]![Employer] = Employer
[LayerSubform]![Contractor] = Contractor
[LayerSubform]![SectionNo] = SectionNo
[LayerSubform]![LabName] = LabName
[LayerSubform]![TestType] = TestType
[LayerSubform]![LayerType] = LayerType
[LayerSubform]![AggType] = AggType
[LayerSubform]![MineName] = MineName
[LayerSubform]![SampleDistance] = SampleDistance
[LayerSubform]![SampleCounter] = i
Next i
Exit Sub
aaa:
MsgBox (" data already Exist")
Exit Sub