Enumerating References in Outlook error - Illegal Function Call

G

Greg J

Hi,

I am trying to enumerate the references linked in Outlook VBA with
mixed results. Sometimes I get an error Illegal Function Call (Error
7952). I have just worked out that this error occurs if MS Access is
not open at the time. If I open Access and just leave a blank window
(ie no database opened), the code works without error. As soon as I
close the access application, the error reappears.

I understand that the references collection comes from the Access
object but how do I enumerate the Outlook references from Outlook VBA
using the Access object without having to have Access open at the time?

MS Access object library is linked in the references collection in
Outlook VBA.

Here is a sample of the code that I am currently trying to get working:

Function fnGetReference(strRef As String) As String

Dim accApp As New Access.Application
Dim ref As Access.Reference
Dim refs As Access.References

Set accApp = Access.Application
fnGetReference = "ERROR"
Set refs = accApp.References <<<< ERROR OCCURS ON THIS LINE
For Each ref In refs
If UCase(ref.Name) = UCase(strRef) Then fnGetReference =
ref.FullPath
Next

End Function
 
G

Greg J

correction to the above...

I do need to have a database open and when I do, the following code
runs without error but returns the references collection of the access
database that is open, not Outlook (as the code would indicate)

Function fnGetReference(strRef As String) As String

Dim ref As Access.Reference
Dim refs As Access.References

fnGetReference = "ERROR"
Set refs = Access.References
For Each ref In refs
If UCase(ref.Name) = UCase(strRef) Then fnGetReference =
ref.FullPath
Next
Err.Clear

Set accApp = Nothing

End Function
 
G

Greg J

correction to the above...

I do need to have a database open and when I do, the following code
runs without error but returns the references collection of the access
database that is open, not Outlook (as the code would indicate)

Function fnGetReference(strRef As String) As String

Dim ref As Access.Reference
Dim refs As Access.References

fnGetReference = "ERROR"
Set refs = Access.References
For Each ref In refs
If UCase(ref.Name) = UCase(strRef) Then fnGetReference =
ref.FullPath
Next
Err.Clear

End Function
 
G

Greg J

correction to the above...

I do need to have a database open and when I do, the following code
runs without error but returns the references collection of the access
database that is open, not Outlook (as the code would indicate)

Function fnGetReference(strRef As String) As String

Dim ref As Access.Reference
Dim refs As Access.References

fnGetReference = "ERROR"
Set refs = Access.References
For Each ref In refs
If UCase(ref.Name) = UCase(strRef) Then fnGetReference =
ref.FullPath
Next

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top