Question : "Declare Function" err - "not allowed as Public members of object modules"

hi all - trying to use code from
http://www.experts-exchange.com/Databases/MS_Access/Q_21757133.html (below) and get error:

The expression On Open you entered as the event property setting produced the following error: Constants, Fixed-lenght string, arrays, user-defined types and Declare statements not allowed as Public members of object modules.

on db or form open UNLESS I comment out the "declare function" 3 lines right below Option Compare.

What am i doing wrong??  would really like it to work!

thanks, wes




*********************

Option Compare Database
Declare Function GetUserName Lib "advapi32.dll" Alias _
       "GetUserNameA" (ByVal lpBuffer As String, _
       ByRef nSize As Integer) As Integer

'Return the user's name.
Private Function UserName() As String
Const UNLEN = 256   ' Max user name length.
Dim user_name As String
Dim name_len As Integer

    user_name = Space$(UNLEN + 1)
    name_len = Len(user_name)
   
    If GetUserName(user_name, name_len) = 0 Then
        UserName = ""
    Else
        UserName = Left$(user_name, name_len - 1)
    End If
End Function

Answer : "Declare Function" err - "not allowed as Public members of object modules"

Hi new_wes,
Is that all the code in the module?
have you added this to a form class?  It needs to be in a module, not a form class.
Dave :-)
Random Solutions  
 
programming4us programming4us