473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need VBA code to copy table from two different databases

Hello,

I have the code below. It used to work but now for some reason access breaks when running with error code 2486, "You can't carry out this action at present time.".

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_archive_Click()
  2. Dim objAcc As Object
  3. Dim objAcc2 As Object
  4. Dim filename As String
  5. filename = InputBox(prompt:="Type your file name here.")
  6. If Len(filename) = 0 Then
  7. MsgBox "No file name chosen"
  8. Exit Sub
  9. End If
  10.  
  11. Set objAcc = New Access.Application
  12. objAcc.OpenCurrentDatabase ("P:IBA Delinquency DB Data.accdb")
  13. objAcc.DoCmd.CopyObject "P:IBA Delinquency DB Archive.accdb", filename, acTable, "tl_delinquency"
  14.  
  15. objAcc.CloseCurrentDatabase
  16.  
  17. Set objAcc = Nothing
  18. MsgBox ("Your data has been archived, " & filename & "!")
  19.  
Any assistance is greatly appreciated!

Thank you!

-Al
Dec 15 '14 #1
9 1765
jimatqsi
1,271 Expert 1GB
Al,
As with any other problem report, it's important to give all of the details. Have you stepped through this with the debugger to see where the error is happening?

Perhaps your drive P: is not available? Maybe it would help if the code included the full path instead of just "P:", even if the full path is only "P:\"

You might try doing this "manually" to see if you can discover anything that is not obvious letting VBA handle it.

Do the DBs involved get compressed from time to time?

Jim
Dec 15 '14 #2
twinnyfo
3,653 Expert Mod 2GB
Your lines 12-13 should be:

Expand|Select|Wrap|Line Numbers
  1. objAcc.OpenCurrentDatabase ("P:\IBA Delinquency DB Data.accdb")
  2.  objAcc.DoCmd.CopyObject "P:\IBA Delinquency DB Archive.accdb", filename, acTable, "tl_delinquency"
You need the backslash, even if the file is in the root directory.
Dec 16 '14 #3
The full path works. Also, the backlash "\" is there on the code. I just took it out when copying.

full path of the code.

P:\Travel Card Program\Delinquency DB\IBA Delinquency DB\IBA Delinquency DB Data.accdb

After the error code pops up. (From the initial inquiry up top). The code below is highlighted:

Expand|Select|Wrap|Line Numbers
  1. objAcc.DoCmd.CopyObject "P:\Travel Card Program\Delinquency DB\IBA Delinquency DB\IBA Delinquency DB Archive.accdb", filename, acTable, "tl_delinquency"
Dec 22 '14 #4
twinnyfo
3,653 Expert Mod 2GB
aflores,

Now that I look at the rest of that line, it looks like you may be using the incorrect method. Try using the Transfer Database method, which allows you to more easily transfer objects between two databases.

Your original post is trying to copy a table as a database....
Dec 22 '14 #5
I had the error 13, "type mismatch" for the code below after modifying to transfer database rather copyobject.

Expand|Select|Wrap|Line Numbers
  1. Dim objAcc As Object
  2. Dim objAcc2 As Object
  3. Dim filename As String
  4. filename = InputBox(prompt:="Type your file name here.")
  5. If Len(filename) = 0 Then
  6. MsgBox "No file name chosen"
  7. Exit Sub
  8. 'ElseIf filename = "Data Entry_tbl" Then
  9. 'MsgBox "Change file name"
  10. 'Exit Sub
  11. End If
  12.  
  13. Set objAcc = New Access.Application
  14. objAcc.OpenCurrentDatabase ("P:\Travel Card Program\Delinquency DB\Delinquency DB Data.accdb")
  15. objAcc.DoCmd.TransferDatabase "P:\Travel Card Program\Delinquency DB\Delinquency DB Archive.accdb", filename, acTable, "tl_delinquency"
  16.  
  17. objAcc.CloseCurrentDatabase
  18.  
  19. Set objAcc = Nothing
  20. MsgBox ("Your data has been archived, " & filename & "!")
  21. [qry_Delinquent 51 subform].Requery
  22.         [qry_Delinquency Frequency subform].Requery
  23.             [tl_delinquency_staging subform].Requery
  24.                                  [qry_list of delinquency subform].Requery
  25.                                                 [tl_delinquency_tracker].Requery
  26.     Application.SetOption ("auto compact"), 1
  27.     Me.TabDelinquency.Value = 0
Dec 23 '14 #6
twinnyfo
3,653 Expert Mod 2GB
Where is the error happening? Which line?

If it is Line 15, then it could be a confusion in the arguments:

Expand|Select|Wrap|Line Numbers
  1. objAcc.DoCmd.TransferDatabase _
  2.     acImport, _
  3.     "P:\Travel Card Program\Delinquency DB\Delinquency DB Archive.accdb", _
  4.     acTable, _
  5.     filename, _
  6.     "tl_delinquency"
Also, is the "Delinquency DB Archive.accdb" the file you are currently in or the DB from where the source table is. Your descriptions and question are not altogether clear, so we have to guess at exactly what you are trying to do.

Additionally, with this method, I don't believe you have to actually open the DB (setting objACC), you just execute the code.
Dec 24 '14 #7
So there's three databases:
  1. Delinquency DB - Front End - this is where the code is
  2. Delinquency DB Data - Store Data - takes data from here
  3. Delinquency DB Archive - Archive Data - store data here
Jan 7 '15 #8
twinnyfo
3,653 Expert Mod 2GB
aflores,

Have you have able to experiment with this method?
Jan 9 '15 #9
The code worked before and It's not working now. I don't know why. I'll keep researching. Thanks Twinn.
Jan 12 '15 #10

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

Similar topics

3
by: Henri | last post by:
Hello, I am quite new to ms-sql and I have a problem : I want to create an SQL request which would copy serveral records from a table in a given database to another table (with exactly the same...
1
by: ChrisA | last post by:
Hi all, we are developing an internal application that involves "Timesheets", "Support" and "Project Management". Imagine that there are 3 different databases for the above scenario, under SQL...
2
by: Bill Moran | last post by:
Boy, I'm just full of questions today ... Is there a way to provide different persistent settings for DateStyle for different databases within the same cluster? Simply put, I've got two...
7
by: ShyGuy | last post by:
Is ther a way to copy a table, from the backend of a split database, into a database on another machine from the front end?
1
by: prabhun2004 | last post by:
hi all i use postgresql database. There are two databases in that namely 'db1','db2'. In 'db1', thers is a table named as 'table_common'. In 'db2', there is a table named as...
1
by: shanthimanooj | last post by:
hi i need the code in qtp Compare two different Databases .that means comp two schemas no of tables,no of colums in a tables,no of rows in a table,
1
by: Dammit | last post by:
Hi! My first post in this great forum. :) Here goes: I need some feedback on best practice (or just possible practice!) on creating a copy of a table from one SQLserver to another SQLserver. ...
18
by: asi242 | last post by:
Hello, Good day to all... I just want to ask.. How would you connect two tables from 2 different databases using PHP scripts? Because, one database that contains customer table is dedicated to...
3
by: alter.fire | last post by:
Hey im trying to do the following in PHP: Connect to 2 different databases, one named complete and one incomplete. My goal is to find whats missing in the "incomplete" database. The fields...
11
by: dougancil | last post by:
I have two different databases on the same server using SQL 2000. Every night database 1 is updated via an automated process. I currently have an query that will then move that data to a "static"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.