byref and byval

cisy
StarLounger
Posts: 77
Joined: 26 Apr 2011, 05:10

byref and byval

Post by cisy »

I would like to know if Access VBA has the similar feature as VB in terms of passing parameters with byref and byval. In the following sample program, the value is changed to true in the sub but when it is passed back to the calling program, it still carries false. :sad:

In the calling program:

dim blnDeleted as boolean
blnDeleted = false
ChkIfDeleted(blnDeleted)
msgbox blnDeleted

...
...
...
end sub

public sub ChkIfDeleted(byRef blnDel as boolean)
...
...
...
blnDel = true
msgbox blnDel
end sub

User avatar
HansV
Administrator
Posts: 78676
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: byref and byval

Post by HansV »

The line

ChkIfDeleted (blnDeleted)

passes blnDeleted as a ByVal argument because you enclose it in parentheses. You should use either

ChkIfDeleted blnDeleted

or

Call ChkIfDeleted(blnDeleted)
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15667
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: byref and byval

Post by ChrisGreaves »

HansV wrote:... because you enclose it in parentheses.
Good call! :evilgrin:
He who plants a seed, plants life.

cisy
StarLounger
Posts: 77
Joined: 26 Apr 2011, 05:10

Re: byref and byval

Post by cisy »

Thanks Hans. Clearly it is different from VB. :evilgrin: