Error when saving new data for employees table

C

Cameron

I have been getting an error num ber 3022 when I click close on this form I
have been working on. I do not understand why the form is doing this. This
table is indexed, but not with a Primary Key. The field allows duplicates but
is filled via and autonumber type.

My close button data is as follows:

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
If Me.Dirty Then Me.Dirty = False

DoCmd.Save
DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox err.Description
Resume Exit_cmdClose_Click

End Sub

The employee table is however linked to other tables. I just do not know how
come this is happening. If I venture to enter data in the table directly it
works fine. If I enable navigation buttons on the form and use the new record
selection from there the records save, but my code will not and thus produces
the anoying error.

Any help would be appreciated...
 
M

Marshall Barton

Cameron said:
I have been getting an error num ber 3022 when I click close on this form I
have been working on. I do not understand why the form is doing this. This
table is indexed, but not with a Primary Key. The field allows duplicates but
is filled via and autonumber type.

My close button data is as follows:

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
If Me.Dirty Then Me.Dirty = False

DoCmd.Save
DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox err.Description
Resume Exit_cmdClose_Click

End Sub


If you can get a Debug button on the error message, use it
to try to identify which line of code is causing the
problem. If there is no Debug button, then place a break
point at the top of the procedure and step throught it one
line at a time until you get the error.

I really doubt if the Dirty = False line is causing the
error.

More likely the DoCmd.Save line is the problem. Are you
aware that DoCmd.Save saves the form's design, not the data
in the current record? In general, it is extremely unusual
and almost always ill advised to modify a form's design on
the fly and therefore DoCmd.Save is a BAD THING to use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top