Results 1 to 6 of 6
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    609

    Using FosUserName In Access 2016

    I haven't used VBA in access for a minute here, but now I am back in it and trying to use this wonderful function in access 2016 but I get this error. What do I need to change so I can use this function?

    https://ibb.co/hLK80YG



    Click image for larger version. 

Name:	Capture.png 
Views:	13 
Size:	30.8 KB 
ID:	40719
    Last edited by jo15765; 01-19-2020 at 05:48 PM. Reason: embedded image

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    48,658
    Try:

    Private Declare PtrSafe Function ...

    Or

    Don't use API function and instead use Environ("USERNAME").
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,987
    See this link fort 3 different methods of getting user name http://www.mendipdatasystems.co.uk/g...ame/4594424315.
    If you really want to use the API, the link includes the code to convert it to 64-bit.
    However I would recommend using either Environ("UserName") or CreateObject("WScript,Network").UserName instead
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

  4. #4
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    609
    Thanks, I'll adapt it to use on a 64x system.

    I'm steering away form Environ("UserName") as this db will be accessed on a few OSX systems and I've read stories of it not working on OSX.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,731
    I've read stories of it not working on OSX.
    I know a guy who was better at this than me, who always used Environ in his db's in a corporate environment where anybody who had Access had the same version. Db's were always properly split and distributed, there were no RunTime versions involved etc. etc. and one day, it just stopped working. He switched over to fosUserName, which fortunately I was already using. I've read about Environ properties getting dropped at times so between that and the other guy's experience, I saw no need to switch. Most of my user properties came from a user class anyway, which means that once the function set the property I didn't need to call it again for anyone's session. I know I'm going to get a bit of blow back on the Environ thing...
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    "Everyone has a photographic memory; some just don't have film." Steven Wright

  6. #6
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,987
    All methods work but personally I see no benefit in using an API for this. It just adds complexity for no reason.
    I'm not sure what relevance OS X has to this as Access doesn't run on an Apple OS.
    Or did you mean Windows 10? If so you've heard wrongly.

    My only concern with using Environ is that the output can be 'spoofed' if you know how.
    Using WScript is just as easy and cannot be 'spoofed' so that's my method of choice in a multi user environment.

    However, all methods work so each to their own ....
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

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

Similar Threads

  1. Replies: 2
    Last Post: 03-25-2019, 12:59 AM
  2. Replies: 6
    Last Post: 03-22-2019, 10:04 AM
  3. Replies: 11
    Last Post: 08-08-2018, 11:23 AM
  4. Replies: 4
    Last Post: 08-07-2018, 05:38 AM
  5. Restrict Access to Form Based on fOSUserName()
    By ricker090 in forum Programming
    Replies: 1
    Last Post: 11-28-2012, 04:07 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
  •  
Tech Forums: Microsoft Office Forums