Automate importing, exporting, or linking data

Depending on the type of data you're working with, you can automate the importing, exporting, and linking of data by carrying out the TransferDatabase, TransferSpreadsheet, or TransferText actions in a macro or Microsoft Visual Basic procedure.

Use a macro

  1. Create a macro.

    How?

    1. In the Database window, click Macros under Objects.
    2. Click the New button on the Database window toolbar.
    3. Add an action to the macro.

      How?

      1. In the Macro window, click the first empty row in the Action column. If you want to insert an action between two action rows, click the selector for the action row just below the row where you want to insert the new action, and then click Insert Row on the Macro Design toolbar.
      2. In the Action column, click the arrow to display the action list.
      3. Click the action you want to use.
      4. In the lower part of the window, specify arguments for the action, if any are required. For action arguments whose settings are a database object name, you can set the argument by dragging the object from the Database window to the action's Object Name argument box.
      5. Type a comment for the action. Comments are optional.
    4. To add more actions to the macro, move to another action row and repeat step 3. Microsoft Access carries out the actions in the order you list them.
  2. Do one of the following to import, export, or link data between the current Microsoft Access database and:
  3. Set the action arguments as appropriate for the action.
  4. Click Save to save the macro.
  5. Run the macro.

    How?

    To run a macro directly, do one of the following:

Use a Visual Basic procedure

  1. Create a Visual Basic procedure.

    How?

    1. To open a module, do one of the following:
      • To open a new standard module, in the Database window, click Modules under Objects, and then click the New button on the Database window toolbar.
      • To open an existing standard module, click Modules under Objects, select the module you want to open, and then click Design.
      • To open a new class module that isn't associated with a form or report, in the Database window click Class Module on the Insert menu.
      • To open an existing class module, in the Database window, click Modules under Objects, select the module you want to open, and then click the Design button on the Database window toolbar.
    2. Declare the function by typing the Function statement.
    3. Type a function name immediately followed by any function arguments in parentheses. For example, the following declaration for the IsLoaded function specifies strFormName as an argument:
      Function IsLoaded (strFormName As String) As Boolean
    4. Add the Microsoft Visual Basic code that performs the operation or calculation that you want the function to perform.
  2. Do one of the following to import, export, or link data between the current Microsoft Access database and:
  3. Click the Run Sub/UserForm command on the Run menu in the Visual Basic Editor to run the procedure.