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!




Reply With Quote
