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!

ADP, Problem saving and closing form when key violation, error 2757

Status
Not open for further replies.

pkahlo

Programmer
Nov 3, 2003
29
US
I am in the process of coverting a jet MDB to an Access Project in SQL. I've noticed some weird behavior in regards to saving data on a form.

My forms are closed using a command button that basically does this:

Code:
    If frm.Dirty Then
        frm.Dirty = False
    End If
    DoCmd.Close acForm, frm.Name

This normally works. I've noticed that when there is a primary key violoation, I get this error:

Run-Time error '2757':
There was a problem accessing a propery or method of the OLE object.

I also get this error if I try to run: "RunCommand acCmdSaveRecord"

However, if I close the form manually (not using the button) or save using the Menu (Records->Save Record) I would get the expected msg box stating there is a primary key violation and you cannot save this record.

Why don't I get a message like that when I run this stuff from code?

If I just run "DoCmd.Close acForm, frm.Name" the form will close and NOT prompt that there is a key violation and it will not save. So that isn't good either.

How do I close a form using a button so that is prompts about a key violation without giving strange errors or just closing with no warning?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top