userid code work for all but 1 form (1 Viewer)

jedder18

Just Livin the Dream!
Local time
Yesterday, 18:29
Joined
Mar 28, 2012
Messages
135
I have a form upon opening a MSAccess 2016 db.
It grabs the UserID.

Option Compare Database
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() 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
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function



On enter of this form it opens to another form containing links to other forms.
On these other forms, they contain an unbound text box grabbing =fosusername() to populate user id on the form.
This works for 6 out of the 7 forms.
I can't get the 1 form to populate. Have done nothing different in this one.
Even delete the button to get to that form and recreated, but, still get compile error. Sub or Function not defined.

What am I missing?


Jennifer:banghead:
 

isladogs

MVP / VIP
Local time
Today, 02:29
Joined
Jan 14, 2017
Messages
18,209
Nothing obvious from your description.

As an alternative try using this instead of all your code
Code:
 Environ("UserName")

It will get the user name from Windows login
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:29
Joined
Feb 28, 2001
Messages
27,138
If you have a general module and your forms can use it, you can declare some public variables in the declaration area of the module (as opposed to the declaration area of any routine). As long as you don't take a debug event that requires a RESET operation, these variables persist for the life of the application. You could easily store the ID you want in this (effectively) global area and reference it from any other form.

Ridders also makes a good suggestion. He's talking about how to get the info. I'm talking about where to keep it once you've got it.
 

jedder18

Just Livin the Dream!
Local time
Yesterday, 18:29
Joined
Mar 28, 2012
Messages
135
It was missing a general declaration on that specific form.
 

Users who are viewing this thread

Top Bottom