I found a link via this forum to Prevent dupes entered by a form
http://www.databasedev.co.uk/duplicates.html ; It works great!!!
However I need help in making it check two fields instead of one.
The below code checks for a duplicate record with a specific dtID. i.e.
Jun07=6 dtID
I have many project with this dtID. I need it to check for the DtID and
ProjectID. To make sure there is not a dupe for ProjectID=4 with DtID =6.
I am desperate for help
Please help. I am just learing VBA, and I am no so good yet.
Private Sub ReportDtID_BeforeUpdate(Cancel As Integer)
Dim DtID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
DtID = Me.ReportDtID.Value
stLinkCriteria = "[ReportDtID]=" & DtID
'Check table for duplicate ID
If DCount("ReportDtID", "tCustImpacts", _
stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Customer Impact for selected Report Date was
previously entered." _
& vbCr & "You will now been taken to the record." _
& vbCr & vbCr & "Verify the Report Date and make changes(as
needed).", _
vbInformation, "Duplicate Information"
If Me.ReportDtID = 1 Then
Me.Undo
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If
'Go to record of original ID
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
Forms!f2CustImpactsEdit.Form!f2CustImpactsEditDetails.Form.Visible =
True
End If
Set rsc = Nothing
End Sub
http://www.databasedev.co.uk/duplicates.html ; It works great!!!
However I need help in making it check two fields instead of one.
The below code checks for a duplicate record with a specific dtID. i.e.
Jun07=6 dtID
I have many project with this dtID. I need it to check for the DtID and
ProjectID. To make sure there is not a dupe for ProjectID=4 with DtID =6.
I am desperate for help
Please help. I am just learing VBA, and I am no so good yet.
Private Sub ReportDtID_BeforeUpdate(Cancel As Integer)
Dim DtID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
DtID = Me.ReportDtID.Value
stLinkCriteria = "[ReportDtID]=" & DtID
'Check table for duplicate ID
If DCount("ReportDtID", "tCustImpacts", _
stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Customer Impact for selected Report Date was
previously entered." _
& vbCr & "You will now been taken to the record." _
& vbCr & vbCr & "Verify the Report Date and make changes(as
needed).", _
vbInformation, "Duplicate Information"
If Me.ReportDtID = 1 Then
Me.Undo
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If
'Go to record of original ID
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
Forms!f2CustImpactsEdit.Form!f2CustImpactsEditDetails.Form.Visible =
True
End If
Set rsc = Nothing
End Sub