I wrote following code to test the difference between byVal and ByRef :
Private Sub Main()
Dim var As Byte
var = 5
Debug.Print "modified by val : " & var
Debug.Print "modified by ref : " & var
Private Sub ModifyByVal(ByVal var As Byte)
var = 10
Private Sub ModifyByRef(ByRef var As Byte)
var = 10
I expected the value of var to be 10 after calling the sub ModifiedByRef.
But it still shows 5.
I wanted to test this because I have a similar issue in my real program. I passed a recordset by val. In the called sub I do a loop through this recordset till EOF. In my mainsub, also the recordset I passed is EOF????
I've learned something new here. Hopefully someone can explain, or you can use it to google and find the answer.
Both of these work, but your syntax does not.
Call ModifyByRef (val)
However, this is unrelated to your real problem. Bytes (and similar variables) are simple, value types. Recordsets are reference types.
When you pass a recordset you don't pass the object, you pass a pointer to the object in memory. Whether you pass that pointer by value or reference makes no difference - both still point to the same address location.