Why does Sub work but not function
I have a form in my app named frmMain
In the form I have a Sub
Public Sub mySub()
End Sub
and a function
Public Funtion GetValue() as Long
GetValue = 100
End Function
Now when I call mySub from another form, I do something like
Dim frM as frmMain
frmMain.mySub()
And that works fine..
But why can't I get the return value of the GetValue() function?
i.e
Dim frM as frmMain
Dim myValue as Long
myValue = frmMain.GetValue()
It returns an error, object reference not set to instance of an object...
Thanks
Re: Why does Sub work but not function
Quote:
Originally posted by greg_quinn
And that works fine..
No it doesn't.
Re: Why does Sub work but not function
Quote:
Originally posted by greg_quinn
I have a form in my app named frmMain
In the form I have a Sub
Public Sub mySub()
End Sub
and a function
Public Funtion GetValue() as Long
GetValue = 100
End Function
Now when I call mySub from another form, I do something like
Dim frM as frmMain
frmMain.mySub()
And that works fine..
But why can't I get the return value of the GetValue() function?
i.e
Dim frM as frmMain
Dim myValue as Long
myValue = frmMain.GetValue()
It returns an error, object reference not set to instance of an object...
Thanks
Sorry but you are all screwed up here (I think:confused: )
It looks as though your frmMain is NOT the startup object of your project. In that case;
Dim frM as frmMain should be
Dim frM as New frmMain
and frmMain.mySub should be
frM.mySub
mySub will have to be Public and so will myValue.
Try that and see what happens.
By the way, I agree with wossname, none of your code can possibly work:bigyello: