Results 1 to 5 of 5
  1. #1
    davidac is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    2

    Use Network Name to gain access to DB

    good afternoon all,
    i have a DB which i want to be able to use the network name of the user to check to see if they are allowed access to the DB. I am currently using the network name for audit purposes but i am strugglnig to get the netwrok name to check the users table in the DB to see if they are allowed access. i have attached the code i think i need to use but this is not appearing to be working. can someone please assist me in my hour of need of what i need to do and where i need to put things.



    Code:
     Dim lngLen As Long, lngX As Long
        Dim strUserName As String
     
        Static strOSName As String
        
        If Len(strOSName) > 0 Then
            FOSUserName = strOSName
            Exit Function
        End If
        
        strUserName = String$(254, 0)
        lngLen = 255
        lngX = apiGetUserName(strUserName, lngLen)
        If (lngX > 0) Then
            strOSName = Left$(strUserName, lngLen - 1)
        Else
            strOSName = vbNullString
        End If
        FOSUserName = strOSName
        
    End Function
     
    usernm = FOSUserName()
    If DCount("Username", "L_Users", "Username='" & usernm & "'") > 0 Then
    'carry on
    Else
    MsgBox "Invalid Username-" & usernm & "- application will close."
    Application.Quit
    
    End If

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Can you be more specific than "this is not appearing to be working"? Do you get an error? Unexpected result?

    You missed the first line of the function, but I assume you're using this:

    http://access.mvps.org/access/api/api0008.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    davidac is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    2
    Hi the function compiles okay but when i close it down and re-open it the DB just re-opens without appearing to check the users table as anyone can log in.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Is that your actual code? If so, the test occurs outside any sub or function, and should be throwing an error. If not, what is the actual code?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I'm assuming you're loading a form when you open the database and the ON OPEN event has your code attached?

    if so, change your DCOUNT to

    DCount("*", "L_Users", "Username = '" & Me.usernm & "'")

    Secondly is your code correctly retrieving the network login name?

    EDIT: if it isn't you can use something simpler like

    dim sCurrUser as string

    sCurrUser = eviron("username")

    then use scurruser in your dcount function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access DB on network
    By Kpax in forum Access
    Replies: 1
    Last Post: 06-28-2010, 06:09 AM
  2. Need To Understand MS Access Across A Network
    By johnmagu in forum Access
    Replies: 8
    Last Post: 05-25-2010, 03:14 PM
  3. can not access over network using runtime
    By Kris Jones in forum Access
    Replies: 1
    Last Post: 03-03-2010, 09:56 PM
  4. MS-access share on network
    By miziri in forum Forms
    Replies: 1
    Last Post: 02-17-2010, 12:28 PM
  5. Access over network
    By hornsby in forum Access
    Replies: 2
    Last Post: 01-06-2009, 02:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums