- Local time
- Yesterday, 21:02
- Joined
- Feb 28, 2001
- Messages
- 29,655
I see this has sprung up again. However, I have to admit when I have had mistaken impressions. I went through the VBA language reference and found some things in the chapter on processing of function/subroutine arguments.
It IS possible to formally declare something ByVal and actually pass in an object. But the catch is that the object must return a value when invoked, because a Let-assign will occur during run-time processing of the invocation. That way, the object's .Value property is evaluated for the Let-assign to the formal (ByVal) parameter/argument. If the object doesn't return a value, you can't do a Let-assign. In that case you get a COMPILE-TIME error, either a Type Mismatch or an Invalid Parameter error. Which is why you CAN pass in something like function DATE(NOW) as an actual parameter to ByVal variable. If the variable that would be the formal parameter cannot accommodate the .Value of the actual parameter, you would get a run-time error of Type Mismatch.
I stand by the fact that I got anomalous results (but not compile-time errors) at places I might have expected when dealing with some Excel and Word internal methods, but acknowledge that it could have been something getting de-referenced unexpectedly somewhere between Access and Excel or Access and Word. It is DEFINITELY a PITA environment when trying to do something tricky.
It IS possible to formally declare something ByVal and actually pass in an object. But the catch is that the object must return a value when invoked, because a Let-assign will occur during run-time processing of the invocation. That way, the object's .Value property is evaluated for the Let-assign to the formal (ByVal) parameter/argument. If the object doesn't return a value, you can't do a Let-assign. In that case you get a COMPILE-TIME error, either a Type Mismatch or an Invalid Parameter error. Which is why you CAN pass in something like function DATE(NOW) as an actual parameter to ByVal variable. If the variable that would be the formal parameter cannot accommodate the .Value of the actual parameter, you would get a run-time error of Type Mismatch.
I stand by the fact that I got anomalous results (but not compile-time errors) at places I might have expected when dealing with some Excel and Word internal methods, but acknowledge that it could have been something getting de-referenced unexpectedly somewhere between Access and Excel or Access and Word. It is DEFINITELY a PITA environment when trying to do something tricky.