Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Addressof-Operator in VBA / MSACCESS97

162 views
Skip to first unread message

Thomas Pomper

unread,
Jan 10, 2001, 4:23:05 AM1/10/01
to
Dear sirs,

I have a problem with the using of the addressof-operator in VBA / Access97.

Please see my little VBA-Module:

Option Compare Database
Option Explicit

Public Function Test()
MsgBox "Test"
End Function

Public Function Test1()
Dim addr As Long
addr = addressof Test

End Function

If I input »addressof« the programmers help show me a list of all functions, also
the function Test. But when I choose this entry and want to leave this line, the
line changes to read, and a messagebox with the error message »Fehler beim
Kompilieren - Erwartet: Ausdruck« (in Englisch: Error on Compilation - Expected:
expression) is showed.
If I try to compile the module, the same occurs. Can you help me?

In my opinion, in the variable addr must stored the address of the function test.

Thank you for your help

Tony Oakley

unread,
Jan 10, 2001, 6:01:40 AM1/10/01
to
Access doesn't have an addressof function I'm afraid, however, there is a work around
- see below, I can't for the life in me remember where I lifted this code form but it
does seem to work.

'Provides Callback functionality in VBA
'May be replaced with AddressOf function in future versions of VBA
'***Important***
'Callback function parameters must exactly match those expected by the API
'otherwise a GPF will result!

Private Declare Function GetAddr Lib "Vba332.dll" Alias "TipGetLpfnOfFunctionId"
(ByVal hProject As Long, ByVal strFunctionID As String, ByRef lpfn As Long) As Long
Private Declare Function GetFuncID Lib "Vba332.dll" Alias "TipGetFunctionId" (ByVal
hProject As Long, ByVal strFunctionName As String, ByRef strFunctionID As String) As
Long
Private Declare Function GetCurrentVBAProject Lib "Vba332.dll" Alias
"EbGetExecutingProj" (hProject As Long) As Long

Public Function AddrOf(strFuncName As String) As Long

Dim hProject As Long
Dim lngResult As Long
Dim strID As String
Dim lpfn As Long
Dim strFuncNameUnicode As String

Const NO_ERROR = 0

'The function name must be in Unicode
strFuncNameUnicode = StrConv(strFuncName, vbUnicode)

'Get the current VBA project handle
GetCurrentVBAProject hProject

If hProject <> 0 Then

lngResult = GetFuncID(hProject, strFuncNameUnicode, strID)

If lngResult = NO_ERROR Then

'Get the function pointer
lngResult = GetAddr(hProject, strID, lpfn)

If lngResult = NO_ERROR Then

AddrOf = lpfn

End If

End If

End If

End Function


Hope this helps

Tony Oakley

Stephen Lebans

unread,
Jan 10, 2001, 4:11:48 PM1/10/01
to
That code was generaously developed and published by Getz and Kaplan. To
understand how to use it I would suggest reading:
http://www.mvps.org/access/api/api0031.htm


HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks


"Tony Oakley" <To...@nospam.softoak.demon.co.uk> wrote in message
news:3A5C4113...@nospam.softoak.demon.co.uk...

Viktor Umanskiy

unread,
Jan 11, 2001, 9:46:37 PM1/11/01
to
A quote from Access Help: "The AddressOf operator appears only in the call
to the API procedure."

Viktor

Thomas Pomper <in...@koegel-leipzig.de> wrote in message
news:523401c07ae6$f0389280$46862ecf@cpmsftngxa06...

michael (michka) kaplan

unread,
Jan 13, 2001, 1:05:40 AM1/13/01
to
Might I also suggest that you redownload the code that has the proper
copyright notices on it, and post it that way in the future?

When one does certain things practically for free, the only reward is thanks
from the people who were helped.... if you strip the names you take that
away, too!

--
MichKa

a new book on internationalization in VB at
http://www.i18nWithVB.com/

"Tony Oakley" <To...@nospam.softoak.demon.co.uk> wrote in message
news:3A5C4113...@nospam.softoak.demon.co.uk...

0 new messages