Insert current record on a form to another table using cmd button (1 Viewer)

saledo2000

Registered User.
Local time
Today, 17:41
Joined
Jan 21, 2013
Messages
94
Hello.
How to write sql Insert statement to insert current record displayed on the form with cmd button. Records in the Customer table are ID_Number, Name and Surname.
I need to insert ID_Number, Name and Surname in the Customer_List table.
Thank you.
 

Falcone203

Member
Local time
Today, 12:41
Joined
Dec 5, 2019
Messages
40
Make an Append query and then view the query in "SQL". Then execute it with your cmd button.
The query should only show those not already in "Customer_List" table or you may duplicate entries. May need an "If" statement to enable the cmd button based on your query results, that may clue you
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:41
Joined
Oct 29, 2018
Messages
21,358
Hi. Is your form unbound? If bound, is it to a different table than Customer_List? If so, then why do you seem to be storing duplicate information in separate tables?
 

saledo2000

Registered User.
Local time
Today, 17:41
Joined
Jan 21, 2013
Messages
94
Hi. Is your form unbound? If bound, is it to a different table than Customer_List? If so, then why do you seem to be storing duplicate information in separate tables?

Because I need to see all records from two tables like in excel sheet. It does not work like a form and subform nested.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:41
Joined
Oct 29, 2018
Messages
21,358
Because I need to see all records from two tables like in excel sheet. It does not work like a form and subform nested.
You should still be able to display the same record twice or more in different forms without storing a duplicate copy of it in another table. For example, you can have to separate forms based on the same table and display the same record in both forms, but only use one table.
 

plog

Banishment Pending
Local time
Today, 12:41
Joined
May 11, 2011
Messages
11,611
Because I need to see all records from two tables like in excel sheet.

You don't achieve that by copying data hither and yon. In a database you achieve this via a query.

Even with an Excel mindset this concept should be evident. If you use one tab to crunch a bunch of data down to one set of values you wouldn't create a macro to copy that row to another tab, you would instead reference the cells you needed.

Same concept in Access, except you link tables together in a query, bring down the data you need and then use that query for your reporting needs.
 

Reshmi mohankumar

Registered User.
Local time
Today, 23:11
Joined
Dec 5, 2017
Messages
101
Because I need to see all records from two tables like in excel sheet. It does not work like a form and subform nested.


first you need to write a code under your command button as
dim sql as string
sql="insert into Customer_table(IDnumber,name,surname) values ('" &textboxname & "','" &textboxname2 & "','" & textboxname3& "')"
docmd.runsql sql
yoursubformname.requery



above referenced textboxes are named in your main form
then create a query to select all from customertable.
then use this query as a data source for your subform on main form.

it looks like excel and what you are inserting from main form.
 

Users who are viewing this thread

Top Bottom