Export & Link a Local Table to a Backend DB? - ms-access

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! :)

Related

How to import query in Access Database?

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"

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 Auto De-link and Re-link an Excel file?

I have a link-table from an Excel file, but sometimes it "breaks" for reasons unknown to me (other people manipulate this file externally and for whatever reason, the link in the database corrupts even though the filename is the same, etc).
The only way I can fix this issue is by delinking the file and then re-linking it. Is there a way to do this automatically when someone opens the database? (I know about autoexec macros and VBA and everything, but I was unable to find VBA code to delete the old link and re-link the file again).
if the file path does not change you can simply relink the source. You can do it to connect all the linked tables to be connected or you can specifically tell one linked table to be reconnected.
pseudo would be:
Go through your table collection
check if the table is a linked table / or any condition
use the .Connect property to set/renew the connectionstring/path for linked tables.
use the .RefreshLink method to reconnect the table
in code it would be something like this:
For Each tdf In db.TableDefs
If tdf.connect <> vbNullString Then
'you can renew the connectionstring if you want by
'tdf.connect = Your_connectionString & ";TABLE=" & tdf.name
'and to reconnect
tdf.RefreshLink
End If
Next tdf

VB does not see Table after DoCmd.TransferDatabase using OpenRecordset

I am using Do.CMD.TransferDatabase to copy in two tables from a second access database. The TransferDatabase command runs, and I see the table in the Access list of tables, but the VB code doesn't see it.
I suspect I've messed up the internal list of tables because I see the tables (
myTable
myTable1
myTable2)
If I leave a table there on purpose, Access seems to "see" the table enough to not over-write it and Access writes a copy, but then the same code does not see the existing table to openit.
Code snippets (sanitized):
{
Dim ws As Workspace
Dim myDB As Database
Set myDB = DBEngine.Workspaces(0).Databases(0)
DoCmd.TransferDatabase acImport, "Microsoft Access", filename, acTable,"myTable", "myTable", False
Dim OriginalInformation As Recordset
Set OriginalInformation = myDB.TableDefs("myTable").OpenRecordset
The code stops on the last line and give the error that the item is not found in the collection.
How do I copy in a table and then look at the contents within the same VB function?
The answer is to use myDB.TableDerrs.Refresh between the import and using the
myDB.TableDefs("myTable").OpenRecordset

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.