Pass object by value not working...



Hi all,

Is there any way to pass an object (created from a custom Class) by
Value in VBA..? I have tried using the ByVal keyword in my procedure
but the object is still being passed by reference (the original object
is modified in the procedure code). Here's my code:

For the Class module (called Test):

Private classVar1 As String

Property Get Number() As String
Number = classVar1
End Property

Property Let Number(ByVal newvalue As String)
classVar1 = newvalue
End Property

In the main Module:

Private Test1 As Test

Private Sub Initiate()
Set Test1 = New Test
Let Test1.Number = "1"

Call AnotherSub(Test1)

MsgBox Test1.Number 'Shows 2 not 1 even though it should be passed
ByVal, not ByRef
End Sub

Private Sub AnotherSub(ByVal t As Test)
Let t.Number = "2"
End Sub

How do I force VBA to pass this Class ByVal or can't it be done..?

Thanks,
Lyndon.

.



Relevant Pages

  • Re: Copying All Records from a Query to a Table
    ... It's almost always significantly better to use SQL than VBA. ... Private Sub Toggle1_Click ... Dim strSQL As String ... You'd be well advised to require variable declaration: ...
    (microsoft.public.access.forms)
  • Re: How to get the name of the command button that was clicked
    ... which regrettably are not available in vba. ... >Private Sub HandleButton(ByVal MyButton As ... > Dim strBookmark As String, strCtrlNam As String, ... > Dim strTxBoxNam As String, strCtrlClkdNam As String, ...
    (microsoft.public.word.vba.beginners)
  • Re: Pass object by value not working...
    ... Private classVar1 As String ... Property Get NumberAs String ... ByVal, not ByRef ... Private Sub AnotherSub ...
    (microsoft.public.excel.programming)
  • RE: Error Passing Arguments, Entry Required Function
    ... Private Sub CS_Exit ... Remember, this is VBA, not VB. ... Public Function func_FieldRequired(FieldX As String, ... 'set focus back to Accounting_Reference_No field ...
    (microsoft.public.access.formscoding)
  • RE: Pass object by value not working...
    ... being passed instead of passing the item itself. ... Private classVar1 As String ... Property Get NumberAs String ... Private Sub AnotherSub ...
    (microsoft.public.excel.programming)