[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

How to call an Access Module function from VB?

What's the best way to call a function in an Access Module from a VB Application.  Using Access97,  I converted an existing macro into a Module using Access's "ConvertMacrosToVisualBasic" menu option.  Have been trying to use a "Database" object in VB to connect to the .mdb file and access the function that I want to call.  No luck.  Not that familiar with VBA and could use a suggestion.  Thanks,
  • 2
1 Solution
jonjonAuthor Commented:
Adjusted points to 200
Try this:
'*************************************************************************** ' RUN MODULE CODE
'*************************************************************************** Private Sub Run_Module_Code()
    Dim accApplication As Application
    On Error GoTo WHOOPS
    Set accApplication = CreateObject("Access.Application.8")     Call accApplication.OpenCurrentDatabase("C:\My Documents\test.mdb")     Call accApplication.Run("My_Module_Code")
    On Error Resume Next
    Call accApplication.CloseCurrentDatabase
    Set accApplication = Nothing
    Exit Sub
    Call MsgBox(Err.Description, vbCritical)
    Resume ERROR_EXIT
End Sub
You should make sure you have a reference to the MS Access 8.0 Object Library in the references dialog (get there from the Project menu).
Note that you can have additional arguments if your module requires them. They go after the module name in the .Run command:
  Call accApplication.Run("My_Module_Code", arg1, arg2, arg3)
jonjonAuthor Commented:
Excellent!  That was exactly what I was looking for.  Thank You.

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now