Solved

MS Access - Can't Access Function in Module

Posted on 2014-02-12
2
507 Views
Last Modified: 2014-02-12
I have the below code.   I get an error when getting to:

    sUserName = modUtilities.GetUserName

I found that I can't get to the function when i right click and select Definition.  Any idea how to resolve?  Its working in another application.

Private Sub Form_Load()

    On Error GoTo Form_Load_Err
    
    If (Not IsNull(OpenArgs)) Then
        DoCmd.GoToRecord , "", acNewRec
    End If
    
    If (Not CurrentProject.IsTrusted) Then
        Exit Sub
    End If
    
    Dim sUserName As String
    sUserName = modUtilities.GetUserName
    
    If IsNull(Me.Title.Value) Then
        Me.CreatedBy.Value = sUserName
        Me.RevisedBy.Value = sUserName
        Me.CreatedOn.Value = Now
        Me.RevisedOn.Value = Now
    Else
        Me.RevisedBy.Value = sUserName
        Me.RevisedOn.Value = Now
    End If
    
    On Error Resume Next
    If (TempVars!NewData <> "") Then
        [Project Name] = TempVars!NewData
    End If

Open in new window


Below is my module (modUtilities)

Option Explicit
Option Compare Database

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetUserName() As String
    
    ' Returns the network login name
    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
    
    strUserName = String$(254, 0)
    lngLen = 255
    
    lngX = apiGetUserName(strUserName, lngLen)
    
    If (lngX > 0) Then
        GetUserName = Left$(strUserName, lngLen - 1)
    Else
        GetUserName = vbNullString
    End If

End Function

Open in new window

0
Comment
Question by:CipherIS
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39855073
just use

Dim sUserName As String
    sUserName = GetUserName()
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 39855091
Thank you.  Weird I had no problems in another application with the same code.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question