By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,491 Members | 879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,491 IT Pros & Developers. It's quick & easy.

VBA (Copying Tables)

P: 18
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


Expand|Select|Wrap|Line Numbers
  1. Private Sub Test()
  2.  
  3. Dim strDBPath As String, strTableName As String, appAccess As Access.Application, dbsCurrent As Database
  4.  
  5.  
  6. strDBPath = "C:\My_Documents\BS.mdb"
  7. strTableName = "Users"
  8.  
  9. 'Create a New Instance of Access
  10. Set appAccess = CreateObject("Access.Application")
  11. Set dbsCurrent = CurrentDb
  12.  
  13.  
  14. 'Open the External Database in Access Window
  15. appAccess.OpenCurrentDatabase strDBPath
  16.  
  17. 'Copies the Users table from Batley Spen DB and pastes into the current All_Users DB
  18. appAccess.DoCmd.CopyObject "C:\My_Documents\All_Weeks.mdb", "TBL_BS", acTable, "Users"
  19.  
  20. End Sub
Apr 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: 78
It should look something like this:
Expand|Select|Wrap|Line Numbers
  1. strDBPath = curpath & "\Barwon.mdb"
Hope it works for you.

Nick
Apr 11 '08 #2

NeoPa
Expert Mod 15k+
P: 31,186
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.
Apr 11 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.