VBA (Copying Tables)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AJHY
    New Member
    • Feb 2008
    • 18

    VBA (Copying Tables)

    Hi

    I am trying to copy tables from one DB to another. That's fine with the code below, but could someone explain how the code would work without having the C:\My_Documents \All_Weeks.mdb code in which is the same path as the DB I have open.

    I have tried Currentdb etc but nothing working.

    Thanks in advance

    Andy


    [code=vb]
    Private Sub Test()

    Dim strDBPath As String, strTableName As String, appAccess As Access.Applicat ion, dbsCurrent As Database


    strDBPath = "C:\My_Document s\BS.mdb"
    strTableName = "Users"

    'Create a New Instance of Access
    Set appAccess = CreateObject("A ccess.Applicati on")
    Set dbsCurrent = CurrentDb


    'Open the External Database in Access Window
    appAccess.OpenC urrentDatabase strDBPath

    'Copies the Users table from Batley Spen DB and pastes into the current All_Users DB
    appAccess.DoCmd .CopyObject "C:\My_Document s\All_Weeks.mdb ", "TBL_BS", acTable, "Users"

    End Sub[/code]
    Last edited by Stewart Ross; Apr 11 '08, 03:37 PM. Reason: Added code tags to VB code - please use tags when posting!
  • nspader
    New Member
    • Mar 2008
    • 78

    #2
    It should look something like this:
    Code:
    strDBPath = curpath & "\Barwon.mdb"
    Hope it works for you.

    Nick

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      You can find the folder of the current database from CurrentDb.Name. This includes the db name too of course, but the folder can easily be extracted.

      Comment

      Working...