Removing a Reference

S

Scott

I'm trying to remove a reference in my function "RemoveReference" below.
CODE 1 works if I hard-code the reference "Calendar" that I'm trying to
remove. My problem is in CODE 2. If I try to pass the reference to the
function I get a "Subscript Out Of Range" error.

Can someone help me with my syntax in CODE 2?


USAGE ***********
call RemoveReference("Calendar")

CODE 1 **********

Function RemoveReference(sLibrary As String)
Dim ref As Reference
Set ref = References![Calendar]
References.Remove ref
End Function

CODE 2 **********

Function RemoveReference(sLibrary As String)
Dim ref As Reference
Set ref = References!sLibrary
References.Remove ref
End Function
 
G

Granny Spitz via AccessMonster.com

Scott said:
Can someone help me with my syntax in CODE 2?

Public Sub removeRef(sRef As String)
Dim ref As Reference
Set ref = Application.References(sRef)
Application.References.Remove ref
Set ref = Nothing
End Sub
 
D

Douglas J. Steele

Function RemoveReference(sLibrary As String)
Dim ref As Reference
Set ref = References(sLibrary)
References.Remove ref
End Function
 
M

Marshall Barton

Scott said:
I'm trying to remove a reference in my function "RemoveReference" below.
I get a "Subscript Out Of Range" error.

USAGE ***********
call RemoveReference("Calendar")

Since I like short procedures when the intent is clear,
here's another version:

Function RemoveReference(sLibrary As String)
References.Remove References(Calendar)
End Function

Note that all of the suggested variations will error if the
name of the library is incorrect.
 

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