Run Module Code

  • Thread starter Thread starter beavetoots
  • Start date Start date
B

beavetoots

I've created macros before that I use to run code. When I try to run this
code, it gives me the following: Microsoft Access can't find the name
<lpbuffer> you enetered in the expression. Yet, if I open the module then
hit run, it runs fine. What the heck am I doing wrong?

This is the code:
Option Compare Database

Option Explicit

' Access the GetUserNameA function in advapi32.dll and
' call the function GetUserName.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

' Main routine to Dimension variables, retrieve user name
' and display answer.

Sub Get_User_Name()

' Dimension variables
Dim lpBuff As String * 25
Dim ret As Long, UserName As String

' Get the user name minus any trailing spaces found in the name.
ret = GetUserName(lpBuff, 25)
UserName = Right(Left(lpBuff, InStr(lpBuff, Chr(0)) - 1), 5)

' Display the User Name
MsgBox UserName

End Sub
 
beavetoots said:
I've created macros before that I use to run code. When I try to run this
code, it gives me the following: Microsoft Access can't find the name
<lpbuffer> you enetered in the expression. Yet, if I open the module then
hit run, it runs fine. What the heck am I doing wrong?

This is the code:
Option Compare Database

Option Explicit

' Access the GetUserNameA function in advapi32.dll and
' call the function GetUserName.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

' Main routine to Dimension variables, retrieve user name
' and display answer.

Sub Get_User_Name()

' Dimension variables
Dim lpBuff As String * 25
Dim ret As Long, UserName As String

' Get the user name minus any trailing spaces found in the name.
ret = GetUserName(lpBuff, 25)
UserName = Right(Left(lpBuff, InStr(lpBuff, Chr(0)) - 1), 5)

' Display the User Name
MsgBox UserName

End Sub


I assume it's the Get_User_Name procedure that you're trying to run. How
are you trying to run it? If by a macro, what are the details of the macro?
 
Dirk Goldgar said:
I assume it's the Get_User_Name procedure that you're trying to run. How
are you trying to run it? If by a macro, what are the details of the macro?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

The only thing that the macro has is the action to runcode ... when i go to
the build ... then to functions ..... in this db, in module1 it only shows
GetUserName ... when I click ok to it, it sticks the following into the
runcode statement for the Function Name:
GetUserName («lpBuffer», «nSize»)
 
beavetoots said:
The only thing that the macro has is the action to runcode ... when i go
to
the build ... then to functions ..... in this db, in module1 it only shows
GetUserName ... when I click ok to it, it sticks the following into the
runcode statement for the Function Name:
GetUserName («lpBuffer», «nSize»)


You're trying to run the wrong procedure. But the RunCode action can only
run functions, not subs, so change your Sub Get_User_Name to a Function.
Then go back to the macro and change the Function Name argument to:

Get_User_Name()
 
Dirk Goldgar said:
You're trying to run the wrong procedure. But the RunCode action can only
run functions, not subs, so change your Sub Get_User_Name to a Function.
Then go back to the macro and change the Function Name argument to:

Get_User_Name()


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Thanks! I know something was off, but I didn't know how to correct it. It
works now :)
 
Back
Top