Import Specifications

exm206

New Member
Joined
Jun 11, 2003
Messages
19
I do a lot of importing text files into Access databases. A lot of times I need to import the same large file into different databases. I end up having to create the same import specifications in different databases. To make a long story short, it would make my life a whole lot easier if I could import the import specifications I already created into another database. Does anyone know if this possible? Thanks for your help.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi,

1- Open the target database.
2- Tools->Options->View : Check "System Objects" to show system objects.
3- Goto Tables
4- See MSysIMEXSpecs and make sure it is empty table (if it is not empty then it means you have saved specifications in this database file) (Also If it doesn't exist then it means there is no specification saved)
5- Delete MSysIMEXSpecs table if exists
6- File->Get External Data->Import : Select database file which has specifications that you want to copy
7- Select MSysIMEXSpecs table to import
8- Click OK to import.

Now you have all specifications imported.

This is already possible by using code in VB(A): This code is supposed to be used in the target database file VBA module (You can goto VBA by pressing Alt+F11 in Office Applications and use Insert->Module to insert a new module).

Code:
Sub ImportSpecs()
    ' C:\SourceDB.mdb is the source database which has specifications
    ' All existing specifications (if any) will be deleted in target database
    CurrentDb.TableDefs.Delete "MSysIMEXSpecs"
    DoCmd.TransferDatabase acImport, "Microsoft Access", "C:\SourceDB.mdb", acTable, "MSysIMEXSpecs", "MSysIMEXSpecs"
End Sub

It is also possible to use this more than one database (say all databases in a specific folder - for example C:\TargetDBPath\)

You can run the following code in Excel/Word VBA or in an Access database which is not the Source database has specifications (a temporary database). You should change the source database file name and target files' path in code with yours.

Please make sure that you get all databases backups before running this code. Better you can try it in a sample folder with a few sample database. Remember, it will REMOVE database specifications from the target database file if any already exists.

Code:
Sub GetSpecs()
Dim accApp As Object
Dim SourceDBName As String
Dim DbPath As String
Dim CurrDB As String

    SourceDBName = "C:\SourceDB.mdb"
    DbPath = "C:\TargetDBPath\"  'Make sure about last slash
    
    Set accApp = CreateObject("Access.Application")
    CurrDB = Dir(DbPath & "*.mdb", vbNormal)
    Do Until Len(CurrDB) = 0
        If Not DbPath & CurrDB = SourceDBName Then
            accApp.OpenCurrentDatabase DbPath & CurrDB
            On Error GoTo errhandler
            accApp.CurrentDb.TableDefs.Delete "MSysIMEXSpecs"
            accApp.DoCmd.TransferDatabase acImport, "Microsoft Access", SourceDBName, acTable, "MSysIMEXSpecs", "MSysIMEXSpecs"
            accApp.CloseCurrentDatabase
            CurrDB = Dir()
        End If
    Loop
    accApp.Quit
    MsgBox "Done", vbOKOnly + vbInformation, "Error"
    Exit Sub
errhandler:
    If Err = 3265 Then
        Resume Next
    Else
        MsgBox Err & " - " & Err.Description, vbOKOnly + vbExclamation, "Error"
        If Not accApp Is Nothing Then accApp.Quit
    End If
End Sub

I hope these help.
Suat
 
Upvote 0

Forum statistics

Threads
1,221,552
Messages
6,160,462
Members
451,648
Latest member
SuziMacca

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top