ByRef doesn't work? (1 Viewer)

smbrr

Registered User.
Local time
Yesterday, 23:06
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.
 

JHB

Have been here a while
Local time
Today, 08:06
Joined
Jun 17, 2012
Messages
7,732
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.
 

AOB

Registered User.
Local time
Today, 07:06
Joined
Sep 26, 2012
Messages
615
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?
 

smbrr

Registered User.
Local time
Yesterday, 23:06
Joined
Jun 12, 2014
Messages
61
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.
 

AOB

Registered User.
Local time
Today, 07:06
Joined
Sep 26, 2012
Messages
615
D'oh! (Are you using Option Explicit at the top of your code??...)
 

Users who are viewing this thread

Top Bottom