Question Locked

Copying a table using VB

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
What is the easiest way to copy data and structure from 1 table to another table within the same database? it doesn't matter if table b is overwritten, I need a way to copy table A to table B

5 replies

by vrm_cummings

Basically, something like this works

global GTempDB as database
Set GTempDB = OpenDatabase(dbName)
gtempdb.execute "drop table tmp",dbFailOnError
GTempDB.Execute "select * into tmp from table1 in '" & gsDatabase & "' where counter = " & Data1.Recordset("counter"), dbFailOnError
gtempdb.close

by tsoft

dim cn as adodb.connection
dim strQry as string

set cn=new adodb.connection

'//Here you can drop Table2 if exists
'//You can copy temporal tables also as if '//this is the case
strQry="select * into #Table2 from #Table1"
cn.execute strqry

by brc_wllms

Where can you find the ADODB in the reference section of module tools menu?
I am using Access 2002 database. Also, where Table2 from Table1, do I put the names of my tables? Lastly, the statement //Here you can drop Table2 etc. are these comments explaining what the next syntax is?

I look forward to hearing from you soon.

by thydzik

DoCmd.CopyObject , "table b", acTable, "table a"

This discussion is closed to new replies.