only save record when command button clicked

P

ploddinggaltn

I have a form with numerous data entry fields on it. I only want the record
to be saved when the saved command button is clicked to prevent partial
record data from being saved. I can't use required entry because some fields
need to stay empty. How would I do this? It must be easy but I just can't
find how to do this. Thanks so much
 
A

Arvin Meyer [MVP]

You don't really need a commaqnd button. Instead use the BeforeUpdate event
of your form to cancel the save if the fields you want to save aren't
filled.

If you do want to save on a command button, you will need to unbind your
form from the data and unbind the controls from your fields. The write the
data to the form in the command button. Something like (aircode):

Sub MyButton_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("YourTable")

With rst
.AddNew
!FirstField = Me.txtWhatever
!SecondField = Me.txtSomeOtherTextbox
' etc.
.UPDATE
End With

rst.Close
Set rst = Nothing
Set db = Nothing
End Sub
 

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