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
Solved

MS Access - Can't Access Function in Module

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

839 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