Event procedure (Insert into Syntax)

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I need to create an event procedure on a form. So that when the field is clicked on it will insert the data in table / form into another table. I am having trouble with the syntax of the insert into statement.
 
Upvote 0
Well, you'd need ADO or DAO to hard-code this, but the cheap, easy, and maybe best (for Access, anyway) way to do this would be to use an Append Query and then call that query in the On_Click event of your command button.
So, first, the query:
Make a new query and under "Queries" select "Append Query". For each field, you can either explicitly write:
Code:
Forms!Your_Form.Form!Your_Field
as the name of each field that you want appended and then select which field it should be appended to in the "Append To" field. Or, if you have a Unique Identifier in each record in your original table (note: I use Autonums in every table as a Unique ID; they're very cheap and very reliable), you can simply add your original table that the data will come from to the query, select every field from your original table that you'd like Appended, and then select your unique ID field and in the Where field, write:
Code:
Forms!Your_Form.Form!Your_Unique_ID_Field
[code]
Note:  If this is an Autonum field, you'd want to leave "Append To" blank, as you don't actually want this number to go into your destination table.
Alright, so that takes care of the query.  Now, to call this query from code, you would write the following behind the form:
[code]
Your_Command_Button_OnClick()
DoCmd.OpenQuery "The_Name_Of_Your_Append_Query", acViewNormal, acEdit
End Sub
And it should work!
 
Upvote 0

Forum statistics

Threads
1,221,545
Messages
6,160,447
Members
451,647
Latest member
Tdeulkar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top