Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Composite primary key

Status
Not open for further replies.

tothemax

MIS
Sep 27, 2001
15
US
I have a table with a composite primary key, name and date. This does not allow a double entry of a person with the same date. However, I would like to, when someone enters a duplicate date, not accept that date and give a message that they already have that date reserved. Any ideas on how to do this coding. I am drawing a blank. Thanks for any help you may be able to give me.
 
Couldn't you trap this by looking at the error message logged for primary key violation? And since you know that this error has occured, you could then tell the user? Or am I missing your point?
 
Try this:
Code:
cmbMyCombo_BeforeUpdate(Cancel As Integer)
If DCount("[Audit ID Number]", "tblMyTable", "[Audit ID Number] = Forms![frmMyFormName]!txtAuditID") Then
   MsgBox ("This account has already been audited this month.  Choose another account to audit.")
   Cancel = True
   End If
End Sub

I have this working perfectly in my database. The txtAuditID is a hidden text box that stores the combined values for the audit id.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
OOps, I left off the "Private Sub" part - kind of important. [wink]

Here is same with correction:
Code:
Private Sub cmbMyCombo_BeforeUpdate(Cancel As Integer)
If DCount("[Audit ID Number]", "tblMyTable", "[Audit ID Number] = Forms![frmMyFormName]!txtAuditID") Then
   MsgBox ("This account has already been audited this month.  Choose another account to audit.")
   Cancel = True
   End If
End Sub

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top