Access - custom "The changes you requested to the table were not succesfull..."

I have set Duplicates(No) to one of my table's ID. Then I created a form with Combobox to select all records from that table and to store selected record in a field of joined table (ID foreign key). If I try to add another record with same ID, Access prompts me with a warning message "The changes you requested to the table were not succesfull...etc).

What I want is to remove this message and create a custom one. Here is what I tried:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim sWhere As String
sWhere = "[ID_Table]=" & Me.Combo5
'
If DCount("*", "Table1", sWhere) > 0 Then 

Cancel = True
Me.Undo
MsgBox " Duplicate"
End If

End Sub

This code executes If I select whatever value from combobox. Here are my tables:

Table1
ID_Table(PK)
Field1
Field2 etc.

JoinTable
ID_Join(PK)
ID_Table1(FK)
ID_Table2(FK)

ID Field that has property Duplicates(No) is in Table1 (PK). How can I get this working correctly ?

Answers


I figured out, what a stupid mistake :

Instead of

If DCount("*", "Table1", sWhere) > 0 Then 

I had to change to

 If DCount("*", "JoinTable", sWhere) > 0 Then 

Code didn't work because I was referencing to wrong Table. Problem solved, thanks for response Matt.


Need Your Help

Why not inherit from List<T>?

c# .net list oop inheritance

When planning out my programs, I often start with a chain of thought like so:

Ruby find max number w/o running method twice

ruby function max

I want to find the max number without running the function twice