Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS Access - Can't Access Function in Module

Posted on 2014-02-12
2
Medium Priority
?
523 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

824 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