Add a record only when a button is clicked

I have a form that has the "data entry" property set to yes. He is tied to the table. When I start filling out a form, it automatically saves it. I do not want this to happen. I want the form to be saved in the table when I click the button. Any easy way to do this? without vba. If I can only do this with vba, let me know how to do it.

+1
source share
1 answer

The best way to do this is with an unrelated form. When the user clicks the "Save" button, you can run a query to update the table from the controls.

Using Recordset

 Dim rs As Recordset
 Set rs=CurrentDB.Openrecordset("MyTable")

 rs.AddNew
 rs!Field1 = Me.Field1
 rs.Update

, , :

 Dim rs As Recordset
 Set rs=CurrentDB.Openrecordset("SELECT * FROM MyTable WHERE ID=" & Me.txtID)

 rs.Edit
 rs!Field1 = Me.Field1
 rs.Update

,

SQL

 INSERT INTO MyTable (Field1) 
 VALUES ( Forms!MyForm!Field1 )

VBA

 DoCmd.OpenQuery "MyQuery"

 CurrentDb.Execute "Query2", dbFailOnError

SQL , .

+1

All Articles