Access 97 passing object ref to subroutine (1 Viewer)

guy.murray

New member
Local time
Today, 02:37
Joined
Dec 1, 2006
Messages
7
Hi,
am trying to pass a textBox object (Text1) to a subroutine as in the following simplified eg...

Public Sub testSub(objRef As Object)
MsgBox objRef.Value
End Sub

Private Sub Text1_AfterUpdate()
testSub (Text1)
End Sub

This just produces an "Object required" Run-time error "424"

Can someone tell me where I'm going wrong?

many thanks

Guy
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 02:37
Joined
Sep 12, 2006
Messages
15,749
i think a text box is a control so the function should be something like

Public Sub testSub(ctrlref as control)
MsgBox (ctrlref.name & " " & ctlref.Value)
End Sub
 

guy.murray

New member
Local time
Today, 02:37
Joined
Dec 1, 2006
Messages
7
Thanks for replying.

Produces the same error message.

Curiously, putting "msgbox text1.Value" before calling the subroutine behaves as one would expect. The Subroutine seems to treate the object reference as synonymous with its Value property.

I wonder what happens with later versions of Access, I'm stuck with '97.

Guy
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 02:37
Joined
Sep 12, 2006
Messages
15,749
yeah

i assumed this would work, but i've just spent 20 minutes playing with it, and I'm getting the same result as you.

i've definitely used this construct in later versions of Access, but i'm not sure now about Access 97.

sorry
 

Bat17

Registered User.
Local time
Today, 02:37
Joined
Sep 24, 2004
Messages
1,687
Private Sub Text1_AfterUpdate()
Call testSub (Text1)
End Sub

peter
 

Users who are viewing this thread

Top Bottom