How to import query in Access Database? - ms-access

I have an access database and I would like to import a query from another database using VBA. However I bump into the following message
Here is my code:
DoCmd.TransferDatabase acLink, "Microsoft Access", FileAdress, acQuery, "RawData", "RawData Imported"
This code says the Table or Query RawData is not available. The problem is I'm sure it exists in the source database.
The FileAdress is also ok. when I change the code to import a table it works (TableName, acTable...)
Does anyone know how to make it work please ?

You can't link queries, only import them.
Use
DoCmd.TransferDatabase acImport, "Microsoft Access", FileAdress, acQuery, "RawData", "RawData Imported"

Related

How to get data from DBF using VBA in MS Access [duplicate]

I have to import .DBF file int MS Access Table On button click.
The file name is SourceTable.dbf ; Access database is StudentDataBase.accdb and the table I want to insert it is named myTable.
First I want to ask: do I need to have the same fields in the table or it can just be a blank table. I have the following sample code:
DoCmd.TransferDatabase transfertype = acImport, databasetype = "dBase III", DatabaseName = "C:/SourceTable.dbf", objecttype = acTable, Source = "SourceTable", destination = "myTable"
Where in the code do I specify the database, where the table is (StudentDataBase)?
And when I run it like that, i get "Run-time error 2507 The 0 type isn't installed database type or doesn't support the operation you chose."
I'm new To Access and VB programming, so please add some guides on how to rewrite that code line.
Thanks!
A quick test suggests that "SourceTable.dbf" is problematic because it does not conform to the old 8.3 file naming convention. I just got Access 2010 to import "C:\Source.dbf" into an Access table named [FromDBF] via VBA using
DoCmd.TransferDatabase _
TransferType:=acImport, _
DatabaseType:="dBASE III", _
DatabaseName:="C:\", _
ObjectType:=acTable, _
Source:="Source", _
Destination:="FromDBF"

exporting access table from one access database to a new access database

Good afternoon,
I need to export table from one database to a new database in the specific folder. Table name is "Detail Report". New database's name needs to be "Detail Report" too. I have been trying multiple codes, but nothing is working.
The most recent code I am trying to use is:
DoCmd.TransferDatabase , acExport, acTable, "Detail Report", "Y:\Charter\working\new folder\"Detail Report.accd", False
Please help and let me know what I am missing.
Thanks
Try with the correct syntax:
DoCmd.TransferDatabase acExport, "Microsoft Access", "Y:\Charter\working\new folder\Detail Report.accd", acTable, "Detail Report", "Detail Report", False
And the target database must exist.
To create a database: DBEngine.CreateDatabase Method (DAO)

Export & Link a Local Table to a Backend DB?

I have a Local table (Table_A) that I want to periodically export/copy to a backend database as (Table_A_Snap). Each subsequent snapshot will overwrite prior snapshots.
The following snippet produces the following result:
Table_A_Snap is created in the Local DB
Table_A_Snap also created in the Backend DB
The desired LINK to the Backend table is not produced
Note: As the code runs I can actually momentarily see Table_A_Snap appear as a LINKED tale, but then it converts to a Local Table (no link)
TempVars!my_path = full path to backend DB
Snippet:
DoCmd.TransferDatabase acExport, "Microsoft Access", TempVars!my_path, acTable, "Table_A", "Table_A_Snap", -1
DoCmd.TransferDatabase acLink, "Microsoft Access", TempVars!my_path, acTable, "Table_A_Snap", "Table_A_Snap"
I am guessing this is a simple syntax issue. Any suggestions to remedy?
Resolved - Bonehead issue - I copied over the newly created LINKED table further down into code - Apologies! :)

How would I transfer and replace my link specifications from one MS Access file to another using vba?

I currently have an Access file with about 30 custom link specs. I would like to transfer these specs into about 30 different access files using VBA. The end goal of this would be to automate quarterly txt data being put into Access according to certain link specifications. I need a code that will replace the tables MSysIMEXSpecs and MSysIMEXColumns in the new Access file with the tables in the main Access file that contains all the VBA code. If you could go one step farther and explain how to then use these specs to import a comma delimited txt file using the spec, that would be great.
Thanks
I believe these two lines of code (Display below) did the job:
DoCmd.TransferDatabase acExport, "Microsoft Access", DatabaseFullPath, acTable, "MSysIMEXColumns", "MSysIMEXColumns"
DoCmd.TransferDatabase acExport, "Microsoft Access", DatabaseFullPath, acTable, "MSysIMEXSpecs", "MSysIMEXSpecs"

MS Access Copy Table Structure Only

I have a number of Linked (ODBC) tables in my MSAccess DB.
I what I want to do is create a copy of each table (preferably the Structure Only).
ive tried,
DoCmd.CopyObject , "NewTableName", acTable, "SourceTableName"
DoCmd.TransferDatabase acImport, "Microsoft Access", _
SrcDatabase, acTable, SrcTable, DstTable, StructureOnly
but these just seem to make a copy of the linked table.
think ive got it sorted, but ill leave it open incase someone has a better solution,
DoCmd.RunSQL ("Drop Table [LocalTable]")
DoCmd.RunSQL ("SELECT * INTO [LocalTable] FROM [ODBCTable];")
Had the same problem. Found out that the "DoCmd.Transferdatabase" worked, but had to use "1" instead of the keyword "True". And if the source table is a linked table the destination table appears as linked as well (with the arrow in the table list), although it really is in the local database.