Varialbe Assigned on Startup

  • Thread starter Thread starter Mike H.
  • Start date Start date
M

Mike H.

I am new to Access but wish to have a variable, UsrID stored upon startup.
This variable would then be used to record who created records, updated
records, etc. I know how to get the Usrid from the network, but where do I
call that code so it is run at opening of the file and then kept in memory?

Thanks.
 
You have 3 options:
1. Use a Public variable Dimmed as Public in a standard module. Assign the
value in the startup code.

2. Use a Public Function with a static variable. Assign the value in the
startup code.

3. Call the funtion that the returns the userid when you need it.

Believe it or not, Number 3 is the best option.
 
This is a function we use in our Access DBs (we still use Access97 but might
work with new versions) to identify the logged in users. Just create a new
module and paste code below. Then you can make calls to the function
FindUser().

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long

Function FindUser() As String

' Retrieve the name of the logged-in WINDOWS user.

' It appears that GetUserName counts the
' trailing null in the length it
' places in lngLen.

Dim lnglen As Long
Dim strBuffer As String

Const dhcMaxUserName = 255

strBuffer = Space(dhcMaxUserName)
lnglen = dhcMaxUserName
If CBool(GetUserName(strBuffer, lnglen)) Then
FindUser = Left$(strBuffer, lnglen - 1)
Else
FindUser = ""
End If

End Function

Hope this helps
 
Sorry about the post. Reading comprehension problem. I agree with Klatuu
about calling the function whenever you need it.
 
Back
Top