Solved

MS Access - Can't Access Function in Module

Posted on 2014-02-12
2
493 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 119

Accepted Solution

by:
Rey Obrero 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now