?
Solved

having option to insert data from 1 table to multiple different tables

Posted on 2011-05-09
5
Medium Priority
?
302 Views
Last Modified: 2012-06-27
exporting data from table and deleting data in table after data exported:

Usually when I move data from 1 table to another and then have data deleted after exported- i will write something like:

Insert into tbl1
select tbl2.*
From tbl2;
//and to delete
Delete tbl2.[ser no], tbl2.[item number], etc...
From tbl2
Where (((tbl2.[ser num] IS NOT NULL)));
But now I am confused- I have a database with 25 tables and user wants capability to send data from any one of 25 tables to any one of other 25 tables-( also deleting data from table after sent)
Is there any short way of doing this?
I have only used command button ot send do it between 2 tables.
thank you
0
Comment
Question by:davetough
  • 3
  • 2
5 Comments
 

Author Comment

by:davetough
ID: 35722077
yes and all tables have same fields
0
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 35722300
Assume that you have a form with two combo boxes cboTblFrom and cboTblTo each containing the listof tables and a button to run the transfer.

You have to create the sql statements and execute them in code.  You can put the code in the click event procedure of  the button.

sub yourbuttonName_Click()

dim strsql
if nz(forms!yourformname!cbotblTo,"") = "" or nz(forms!yourformname!cbotblFrom,"") = "" then ' not selected
msgbox "Select both tables first"
exit sub
end if

strsql = "Insert into " & forms!yourformname!cbotblTo & Select * from " & forms!yourformname!cbotblFrom
Currentdb.execute strsql, dbfailonerror

strsql = "Delete * from " &  forms!yourformname!cbotblFrom
Currentdb.execute strsql, dbfailonerror
End sub


Backup before testing.
0
 

Author Comment

by:davetough
ID: 35723321
hello peter57r,
am attaching database sample - having trouble with select statement not sure why?
do you any reason for problem
thank you
sample.mdb
0
 
LVL 77

Expert Comment

by:peter57r
ID: 35727148
Sorry, my copy and paste lost a ".
Change this line..

Strsql = "Insert into " & forms!frmExportTables!cboTblTo & " Select * from " & forms!frmExportTables!cboTblFrom
0
 

Author Comment

by:davetough
ID: 35727341
thank you
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question