PDA

View Full Version : Solved: Error 91



ben.oates
04-01-2008, 05:44 AM
Hi all,

Another day of confusion for me. Take a look at this:

Public Sub testIt()
Dim docURI As String
docURI = "myURI"
Dim wf As New WorkFunctions
Dim hl As New Hyperlink
Set hl = wf.URIClean(docURI)
MsgBox hl.Address & " " & hl.ScreenTip & " " & hl.TextToDisplay
End Sub

WorkFunctions is my Class Module. URIClean is definitely a public Function in that module that returns Type Hyperlink (shown below). For some reason, when I try and call the function I get an Error 91: Object variable or With block variable not set on the "hl = wf..." etc.

I have tried it with/without Set and New statements on that line and the 2 above and I still get the same error on the same line.

Any ideas, please? Online help tells me to do what I have already tried. What am I missing?

Public Function URIClean(cleanMe As String) As Hyperlink
cleanMe = Replace(cleanMe, "%2F", "/")
cleanMe = Replace(cleanMe, "%2D", "-")
cleanMe = Replace(cleanMe, "%2E", ".")
cleanMe = Replace(cleanMe, "%5F", "_")

URIClean.Address = cleanMe

cleanMe = Replace(cleanMe, "%20", " ")

URIClean.TextToDisplay = Right(cleanMe, InStrRev(cleanMe, "/"))
URIClean.ScreenTip = "Click here to access " & URIClean.TextToDisplay
End Function

ben.oates
04-01-2008, 05:53 AM
Ok... After stepping in, I find out the error falls on the line URIClean.Address = cleanMe in URIClean because URIClean Is Nothing. How do I instantiate (I think that's right) the object if I've declared it already?

ben.oates
04-01-2008, 06:51 AM
Ugh... found a fudge so vile it makes my skin crawl.

Apparently a Hyperlink has to be a child of another object. It cannot be instantiated on its own and it cannot be a child of Field - as I was working with a database table and assumed that the Hyperlink type had something to do with the Hyperlink column type.

I was wrong. The hyperlink column is just a memo field where you have the following syntax:

<link name>#<link address>

So you just put it in like that and everyone is happy.