Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Access - Can't Access Function in Module

Posted on 2014-02-12
2
Medium Priority
?
516 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

670 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