How do you add a record

  • Thread starter Thread starter Greg Ripper
  • Start date Start date
G

Greg Ripper

How do I add a record in single for view with a button instead of using the
navigation buttons?

I have a form that I use the close form button close, but it will not give
the error message about having a duplicate primary key.

Is there another way to enter the data so that the data is entered and tested
before the form closes?

Rip
 
This is a very long-standing bug in Access. As you found it *silently* loses
your entry when you use the Close action if there is any reason the record
cannot be saved (such as duplicate key value or required field missing or
validation rule not met, or ...)

The workaround - once you realise that Access is losing your entry - is to
code to save the record before using the Close action:


Private Sub cmdClose_Click()
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
End Sub

If the save fails, you receive an error message, and so the close line never
executes. Use error handling to handle the error.
 
Works Great! Thanks
Rip

Allen Browne said:
This is a very long-standing bug in Access. As you found it *silently* loses
your entry when you use the Close action if there is any reason the record
cannot be saved (such as duplicate key value or required field missing or
validation rule not met, or ...)

The workaround - once you realise that Access is losing your entry - is to
code to save the record before using the Close action:


Private Sub cmdClose_Click()
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
End Sub

If the save fails, you receive an error message, and so the close line never
executes. Use error handling to handle the error.
 

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

Back
Top