ByVal / ByRef :: Function needs to return value unchanged

C

Clif McIrvin

Passing a function argument by value is not doing what I expected
it to:

I expect

Me.JobID = "ABC" '(simulate user input)
Me.JobID = EnterInit(Me.JobID)

to leave JobID with the value of "ABC", but it returns as Null.


Private Function EnterInit(ByVal vValue As Variant) As Variant
rem v = vValue
Me.ContractorFind = Null
Me.JobID = Null
Me.JobIDPart = Null
Me.JobName = Null
Me.JobNamePart = Null
ReadyToFind = True
eiReturn:
EnterInit = vValue 'return parameter to caller
rem EnterInit = v 'return parameter to caller
End Function


By single-stepping through the function with the locals window open
I observed that vValue changed from "ABC" to Null when the
Me.JobID = Null statement was executed -- which I would expect
if passing by reference.

My soulution was to add the two lines of code I have shown as 'rem'.

Am I missing something here?
 

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