modify to two fields instead of one PLEASE Help

deb

Active Member
Joined
Feb 1, 2003
Messages
400
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
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Deb, you can go down the route of checking for 2 fields but you may find it easier to create a compound primary key.

You will need to:
1. In a query, check for any duplicates (you can do this with a concatenated field, then count the occurrences).
2. Once this is clean, go to the table design. Ctrl-click the 2 fields, then select the Primary Key symbol. This will prevent users from duplicating the combination, without any code required from you. It will also force them to enter data into both fields, so you won't have gaps in your data.

Denis
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,082
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top