Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004

    Question Unanswered: Passing a variable from excel vba to access.


    I have been struggling with this for about a week now and need some help.
    I have an Access Database with a macro that runs a simple (3 variable query). For simplicity and easy of use, I would like to define the 3 variable in excel and run a macro that will open access and feed it the variables.

    So far, I am able to open the access database and start the macro, however I am not able to send the 3 variables from excel to access.

    Here is the code in excel that opens the database:

    MsgBox "Now locate the Access Database"
    accessfilex = Application.GetOpenFilename(FileFilter:="Microsoft Access Database(*.mdb),*.mdb", Title:="Access Database")
    Set appAccess = CreateObject("Access.Application")
    appAccess.Visible = True
    appAccess.OpenCurrentDatabase accessfilex

    This calls the macro (hospnamex is the variable I want to pass).
    appAccess.DoCmd.Run (createexcelhosptemp(hospnamex))

    Here is the macro:
    RunCode createexcelhosptemp (hospnamex)

    The error says something to the effect of: Access is looking for a variable.

    I do not want to have Access pull the data (ie- look for the excel sheet).
    Does anyone have any ideas?

  2. #2
    Join Date
    Feb 2004
    try this link: "Excel 2002 VBA: Interacting with Other Office Applications"

Posting Permissions

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