Database Table Copy

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Database Table Copy as PDF for free.

More details

  • Words: 253
  • Pages: 2
'************************************** ' Name: Database Table Copy ' Description:This code will copy all fi ' elds from all tables in a database and a ' dd them to another identical database. My company has Rep submitting database reports all the time. I need To append the data from the reports database to a live database. At first I was running querys I had made in the database but our file structure changed and that was no Long an option. This is about as simple as it gets but someone might find it useful. ' By: Shawn Jetton ' ' Inputs:Call the function like this. AddData "C:\My Documents\Test\From.mdb", "C:\My Documents\Test\To.mdb" ' ' Side Effects:None that I know of. ' 'This code is copyrighted and has' limited warranties.Please see http://w ' ww.Planet-Source-Code.com/vb/scripts/Sho ' wCode.asp?txtCodeId=8780&lngWId=1'for details.'**************************************

Public Sub AddData(DataFrom As String, DataTo As String) Dim Dim Set Set

dbFrom, dbTo As Database rsFrom, rsTo As Recordset dbFrom = OpenDatabase(DataFrom) dbTo = OpenDatabase(DataTo)

For n = 0 To dbFrom.TableDefs.Count - 1 'This search out on table in your databa ' se If dbFrom.TableDefs(n).Attributes = 0 Then Set rsFrom = dbFrom.OpenRecordset(dbFrom.TableDefs(n).Name) Set rsTo = dbTo.OpenRecordset(dbTo.TableDefs(n).Name) End If 'Loops through all fields in table and c ' opies from dbFrom to dbTo. Do Until rsFrom.EOF rsTo.AddNew For i = 1 To rsTo.Fields.Count - 1 If rsFrom.Fields(i) = "" Then Goto NoField rsTo.Fields(i) = rsFrom.Fields(i) NoField: Next i 'This updates and moves to the next reco ' rd in the from database rsTo.Update

rsFrom.MoveNext Loop Next n dbFrom.Close dbTo.Close End Sub

Related Documents

Database Table Copy
October 2019 5
Database
November 2019 73
Database
November 2019 74