How to refer to a Multi-Field Primary key? (1 Viewer)

namu

Registered User.
Local time
Today, 03:15
Joined
Dec 30, 2014
Messages
26
Hello,

I have a table with 2 fields set as primary key. One is the ProjectID and the second is CostAccountID, when both are combined they will become a unique key.

I want to replace the default warning message of access to prevent the duplicate entry. To do this, i used dcount function but i seem to have problem in referencing the primary key.

I would be willing to accept suggestions too. :)

Code:
Private Sub CostAccountID_BeforeUpdate(Cancel As Integer)

If DCount("CostAccountId", "tblRates1", "ProjectID = " & Me.ProjectID) > 0 Then
    MsgBox "Duplicate Record"
    Me.Undo
    End If
  

End Sub
Thank you and kind regards,

namu
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:15
Joined
May 7, 2009
Messages
19,246
Private Sub CostAccountID_BeforeUpdate(Cancel As Integer)

If DCount("*", "tblRates1", "ProjectID = " & Me.ProjectID & " And CostAccountID = " & Me.CostAccountID) > 0 Then
MsgBox "Duplicate Record"
Me.Undo
End If


End Sub
 

namu

Registered User.
Local time
Today, 03:15
Joined
Dec 30, 2014
Messages
26
Great! that solved my problem.

Thank you very much. :)
 

Users who are viewing this thread

Top Bottom