How to violate a constraint?

and is AggiungiAzienda.Denominazione the name of the control on your form?

I guess it isn't, i think it is Anagrafica Aziende, but I am not sure because the name of that property is translated in my language in a way I cannot be sure of what I'm saying, and I'm making a mess.
 
If I compile, I receive an error message: not unique name detected, at this point of the code:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
 
Ok, it works!!! I am deeply grateful to you!
The only thing I cannot understant, is why the DBMS sends me a warning in italian, and not in english as it is in the conde. Actually I thought the output was
as the following string:

Code:
"this name already exists, do you still want to save it?"
 
new one on me!

Perhaps you have a utility which translates for you?
 
'it doesn't work' is not very helpful, please provide further detail - does it still update if the user doesn't say yes? or doesn't update? Do you get an error message? if so what is the error number and description? or something else?

Please also post your VBA code and details of your form recordsource and the table [Anagrafica Aziende]
 
You are right, I didn't go on, because of the shame. Excuse me,now I have to go home, and take a deep breath, As soon as I can I try to contact you again. Thx for all, with heart.
 
There is no shame in learning:)

Sono sicuro che si tratta di un problema molto semplice da risolvere
 
OK, thanks a lot for the encouragement. Now I try to think about the questions you have let to me to help me. Once I have a sensible answer I contact you.

p.s. congratulations for your italian. :)
 
First thing I can tell you are these:
don't take into consideration what I told you about the message in italian, it was a misunderstanding.
 
Later I try to let you know what I have understood about the code fragment you sent me:

Code:
dim rst as recordset
set rst = currentdb.OpenRecordset("SELECT * FROM [Anagrafica Aziende] WHERE Denominazione='" & me.[AggiungiAzienda.Denominazione] & "'")
if not rst.EOF then 'there is a duplicate
    if msgbox("this name already exists, do you still want to save it?",vbyesnocancel,"duplicate")<>vbyes then
        cancel=true
    end if
end if
set rst=nothing

I pasted it between the first and the last line, just like you explained me.
I would add that when I make the debug (or at least that is what I think I do), I receive no messages by the compiler (or debugger, dunno).

p.s. I hope I wrote the same code I pasted on the database, this is because I cannot open that file at the moment.
 
The DMBS lets the user add duplicate names. I say that to try to answer your question:

Code:
does it still update if the user doesn't say yes? or doesn't update? Do you get an error message?

no error messages are displayed then.
 
about the code:
what I've understood up to now, is that the two if(s) are used to build a logical condition to discern if it's the case to show the warning message to the user which is inserting a data to the Denominazione field. Before the if(s) there is a select command in which are taken all fields [*] of the table Anagrafica Aziende, when it's true the condition... I make confusion at this point...

I add that, this statement involves the following elements: the table Anagrafica Aziende, the field Denominazione AND the form AggiungiAzienda. I'm not sure I have understood the meaning of the term "form", it could be because there's a name in italian that could be a false friend of this term. I guess that "form" has the meaning of the term "maschera" in italian.

I may have understood too little, I guess.
 
Last edited:
Before the if(s) there is a select command in which are taken all fields
[*] of the table Anagrafica Aziende, when it's true the condition... I make confusion at this point..
The code is checking if a record already exists with that name - if it does then eof (end of file) is false - it is the equvialent of the sql Exists function. The * is irelevant, it doesn't matter whether you return all fields or just one, the point is - does the record already exist. I use * because it give the db a little bit less work to do so it is a little quicker and less to type.

I'm not sure I have understood the meaning of the term "form"
A form is one of the objects in the access db and is how you should be having the user access the tables - see Form1 below
attachment.php
 

Attachments

  • ScreenHunter_05 Mar. 28 00.32.jpg
    ScreenHunter_05 Mar. 28 00.32.jpg
    8 KB · Views: 112
Hi CJ_London,
thx for the message.
Now it's clearer, I can say that the terms you told me to substitute are correct.
I send you a pic to show you where I go, and what I do to try to make debug. I only click on the first line (orange) where it's written "Compila prova contatti"; after I have saved the file.
The immediate window on the bottom doesn't show any message.
That's all, unfortunately I still can duplicate data into Denominazione field, so I'm wrong somewhere, but I still can't find where, which is frustrating because I feel I am closed to the solution.
 

Attachments

  • DEBUG_DETAIL.png
    DEBUG_DETAIL.png
    43.3 KB · Views: 73
Here it is the pic of the window where I pasted VBA code. I took the screenshot after the debug.
 

Attachments

  • VBA_CODE_WINDOW.jpg
    VBA_CODE_WINDOW.jpg
    98.1 KB · Views: 66
I think I see the problem.

You appear to be referring to the form control incorrectly - try

me.Denominazione

instead of

me.[AggiungiAzienda.Denominazione]
 
Ok, I did. Now I cannot duplicate terms. What is absurd is the fact I receive an error message (I am trying to duplicate data in primary key, or in index or in ?relation?), and not a warning in english. The Denominazione field WAS primary key, but I decided to change the field in which to applicate the primary key.

I send you a pic showing a detail of the structure.
 

Attachments

  • STRUCTURE_DETAIL.jpg
    STRUCTURE_DETAIL.jpg
    92.9 KB · Views: 75
Situation doesn't chance if I clear the code. I cannot duplicate data, in both cases (neither with the code nor without).
I add that Denominazione field is not indexed on the table Anagrafica Aziende.
 
The reason that why I decided to try to violate a constraint is that, who projected this database set the primary key on the Denominazione field, but I don't want it to persist because of the fact that I prefer allow inserting duplicates in case of omonimy. So I have removed the primary key, but I want the user to be notified by a warning message at least.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom