Results 1 to 3 of 3

Thread: [RESOLVED] Calling Access from Excel

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Posts
    223

    Resolved [RESOLVED] Calling Access from Excel

    Three part question.

    First question
    I have an Excel/VBA sub that calls Access/VBA sub:

    Excel code:
    Code:
    Sub testAccessSub()
        Dim myAccess As Access.Application, oStr As String
    
        Set myAccess = New Access.Application
        myAccess.OpenCurrentDatabase Worksheets("main").Range("database")
    
        myAccess.Run "testSub", "test string", oStr
        myAccess.Quit
        Set myAccess = Nothing
        
        Debug.Print oStr
    End Sub

    Access code:
    Code:
    Public Sub testSub(iString As String, oString As String)
        oString = iString & "_ack"
    End Sub

    It seems to work (the output string is correct), but twice now after running it, Excel crashed a few seconds after the Sub finished.

    In my experience, when a program crashes at a strange time like that, it's usually indicative of a memory problem. Maybe a dynamic variable that's unallocated. Maybe overwriting an allocated variable's memory. This is the first time I'm playing around with calling another application like this, so I'm wondering... can someone please tell me if I'm doing it correctly? Any problem with this code? Is it necessary to set myAccess to Nothing? I would think Excel's garbage collector handles that when the sub goes out of scope.


    Second question
    Is there a way to debug the Access side in the VBE? (Is there any way to set a breakpoint in the Access code?)



    Third question
    The above code demonstrates input and output parameters for a Sub. Is there a way of calling an Access VBA *function* (as opposed to a Sub)?

    Thanks!
    Last edited by caffeine; May 31st, 2015 at 06:30 PM. Reason: Thought of something I forgot to ask.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width