Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Question Unanswered: import tables at startup

    Hi everyone,

    I'm working on a database which holds all the courses each of our user sfollowed in the past.
    We already have a (third-party) database (let's call it dbBought) containing all the needed user-information (name, user-ID, ...), but I'm not allowed to modifiy anything in this database.
    So I created a new database (let's call it dbOwn) with several tables and I planned to import some tables of dbBought.
    But because dbBought is daily updated, I want to import the needed tables everytime I start up my database. How can I do this automatically?
    PS: I intended to link the tables instead of importing, but we had a discussion with the third-party db-supplier because we had a lot of problems with that db and the supplier said it was because of the linking.
    So linking is not an option anymore.

    Thanks

  2. #2
    Join Date
    Aug 2002
    Location
    Northampton, England
    Posts
    266
    You could use the TransferDatabase method to import the tables.

    Function ImportTables()
    On Error GoTo ImportTables_Err

    DoCmd.TransferDatabase acImport, "Microsoft Access", "FullPath\DatabaseName.mdb", acTable, "TableNameSource", "TableNameDestination", False


    ImportTables_Exit:
    Exit Function

    ImportTables_Err:
    MsgBox Error$
    Resume ImportTables_Exit

    End Function

    Just call the function from the Autoexec macro and it will run on startup.
    Do bear in mind that this does not check if the table exists. If you are just importing the whole table data, it won't matter. However if you are adding data from source table to destination table, it will overwrite what is already there. If the latter is the case, I would suggest you import to a temporary table, then copy the required data to the correct table.

    David

  3. #3
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243
    Thanks for your reaction.

    I tried following for importing tblSource of Source.mdb in tblDestination of current db, but running it will not affect tblDestination.
    Did I do anything wrong?


    Private Sub importTables()
    On Error GoTo ImportTables_Err

    DoCmd.TransferDatabase acImport, _
    "Microsoft Access", _
    "C:\Source.mdb", _
    acTable, _
    "tblSource", _
    "tblDestination", _
    False

    ImportTables_Exit:
    Exit Sub

    ImportTables_Err:
    MsgBox Error$
    Resume ImportTables_Exit

    End Sub


    Another question :
    Source.mdb is password-protected.
    Can I include this in the code so I don't hane to input it anytime?


    Thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •