ByRef doesn't work?

smbrr

Registered User.
Local time
Today, 10:45
Joined
Jun 12, 2014
Messages
61
Hello everyone.

Technically this is on Excel VBA since I open Excel from Access and work with it, but I don't think it matters since the problem here is clearly the passing into my function by ref.

I don't get my issue at all, and I'm even pretty sure it worked just fine until yesterday and I literally didn't touch anything.

Here's my function:
Code:
Public Function MaJBFE(ByRef slctn As Range)

Here's how I call the function:

Code:
ElseIf Selection.Rows.Count > 1 Then
            MaJBFE Selection

The problem is that once in the function, my "slctn" object is "nothing".

I tried all of the following and more:
Code:
Dim rng as Range
Set rng = Selection
MaJBFE rng
Code:
Call MaJBFE(Selection)
Code:
MaJBFE (Selection)

The selection never passes into the function. What is going on here?

Thanks.
 
Is the below code running in MS-Access?
If yes then I think you've to set the reference to Excel, then Range, Selection etc. is unknown for MS-Access.
 
Can you confirm that Selection (or the range variable that you set to the selected range) is present and correct before you call the function? In other words, if you debug and watch Selection.Address (or rng.Address) at the point just before you call the MaJBFE function, does it hold the appropriate address? Or is it Nothing there as well?
 
Well, I seem to have wasted everyone's time and especially my own.

I made a typo within my function and tried to access "sltcn" instead of "slctn"... the selection was passing through since the start.

Sorry guys.
 
D'oh! (Are you using Option Explicit at the top of your code??...)
 

Users who are viewing this thread

Back
Top Bottom