How to use a button for data entry

G

Guest

I have a form that I'm using for data entry. I've attached a button that
adds a new record. The problem is that it also updates records as they are
entered and the user tabs to the next entry.

Is there a way to only allow additions by using the "Add" button. The form
is setup for Data Entry and to Allow Additions. Thanks in advance.
 
B

Brian Bastl

Does your form have a recordsource, or is it unbound? What is the button's
code? Does it explicitly save the current record, or does it move you to a
new record?

Brian
 
G

Guest

Sorry for the late response... The form does have a record source. The
button's code is:

DoCmd.GoToRecord , , acNewRec
 
B

Brian Bastl

btee,

First, I'd set the form's cycle property to 'Current record'. The setting is
found on the 'Other' tab of the form's property sheet.

And then I'd suggest using the form's BeforeUpdate event procedure to check
whether the current record should be saved or discarded. This will fire if
you try to close the form or move to a new record, as long as the record has
changed (been dirtied).

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Do you want to save changes?", vbYesNo) = vbYes Then
Cancel = False
Else
Cancel = True
Me.Undo
End If

End Sub

HTH,
Brian
 
G

Guest

Thanks - that worked!

Brian Bastl said:
btee,

First, I'd set the form's cycle property to 'Current record'. The setting is
found on the 'Other' tab of the form's property sheet.

And then I'd suggest using the form's BeforeUpdate event procedure to check
whether the current record should be saved or discarded. This will fire if
you try to close the form or move to a new record, as long as the record has
changed (been dirtied).

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Do you want to save changes?", vbYesNo) = vbYes Then
Cancel = False
Else
Cancel = True
Me.Undo
End If

End Sub

HTH,
Brian
 

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