+ Reply to Thread
Results 1 to 3 of 3

Copy Database File And Save to Desktop

Hybrid View

  1. #1
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Copy Database File And Save to Desktop

    Hi,
    Let's say I have a database called testTemplate.mdb in c:\ which is a template-like database where i import data to.

    Is there a way for me to copy the testtemplate.mdb and past it to my desktop with file name test.mdb.

    I don't want to copy any data from the database, just the table's + queries

    I would like this to be done via a macro... In order for me to execute other macro's to copy data from excel to that test.mdb file on desktop.
    Last edited by pr4t3ek; 11-13-2008 at 11:03 PM.
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  2. #2
    Registered User
    Join Date
    10-04-2008
    Location
    uk
    Posts
    26
    Hi

    something like this might work. It makes a copy of the database then deletes any table relationships (otherwise table records can't be deleted) and then deletes table records.

    Sub copymyDB()
    
    Dim Sourcedb As String
    Dim Destdb As String
    Dim mydb As DAO.Database
    Dim mytable As TableDef
    Dim i As Integer
    Dim rls As Relation
    Dim mySQL As String
    
    Sourcedb = "C:\TestTemplate.mdb"
    Destdb = "C:\test.mdb"
    
    'Copy Database
    FileCopy Sourcedb, Destdb
    
    Set mydb = DBEngine.OpenDatabase(Destdb)
    
    With mydb
    
    'Delete any Relationships
        For Each rls In .Relations
            mydb.Relations.Delete (rls.Name)
        Next
    
    'Delete Table Records
        For Each mytable In .TableDefs
            If Left(mytable.Name, 4) <> "MSys" Then
                mySQL = "Delete * FROM " & mytable.Name & " in '" & Destdb & "'"
                .Execute mySQL
            End If
        Next
    
    End With

  3. #3
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    excellent!
    for some reason i was getting an error with ".Execute mySQL"
    I commented it out and the macro work's so i guess that's fine.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1