Capture Global User Variable

Deb in LA

Registered User.
Local time
Today, 02:32
Joined
Apr 14, 2000
Messages
19
Hi - it looks like my post did not post for some reason - so if it does later, I apologize for a dupe post...

I do not want to use ACCESS's built in security to establish user logon id's.

I would like the user to type in their "userid" on a main form into a text box. In the after update event, I wish to declare this as a global variable to be used whenever "userid" is referenced anywhere else in the program (i.e. on an input form---displaying current user's id)
The variable should clear when the program exists.

Is this a matter of declaring a sub instead of a private sub in the after update event of the text box? or do i have to create a module?

Also--what happens when 2 users are using the program at the same time?

Thanks in advance.
Deb
 
Set Global gintUserID as Integer in a module you can call basGlobals. But if you have multiple users (assumed) you will need to split the database so that each simultaneous user is setting the gintUserID in the basGlobals of their respective front-end apps.
 
Thanks. Split the database...hope you mean load the program on their local drive and place the data on the network. That's what I was planning to do. Let me know if this is wrong.
Deb
 
I'm not sure if this is what you're looking for, but I use a global module that captures the user's Windows ID automatically:

Option Compare Database
Option Explicit
Public lpUserName As String
Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long
Const NoError = 0

Sub GetUserName()
Const lpnLength As Integer = 255
Dim Status As Integer
Dim lpName As String

lpUserName = Space$(lpnLength + 1)
Status = WNetGetUser(lpName, lpUserName, lpnLength)

If Status = NoError Then
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
Else
MsgBox "Unable to get the name."
End
End If

End Sub


To reference the value on a form, I use a form procedure that sets the value of the text box to the variable "lpUserName". For example, I sometimes use this method as a means of setting an audit trail when someone changes a record:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Call GetUserName
Me.LastUser.Value = lpUserName
Me.ModDate.Value = Now
End If

End Sub

"LastUser" is a text box I create on my form that is hidden to the user (so the value cannot be altered), but references a field in the table. You can use the same principle in a message box or to complete a visible field:

Private Sub Form_Load()

Call GetUserName
Me.MyTextBox.Value = lpUserName

End Sub

where "MyTextBox" is the name of the text box you have created.

In a message box you would use it like this:

MsgBox "The user is: " & lpUserName


As long as the database is split, and assuming each user is running a desktop version of the front-end, this will not cause a conflict with multiple users.

Hope this helps.
 
Thanks -- I will give it a try next week--I never thought of capturing the Windows login id.
Deb
 

Users who are viewing this thread

Back
Top Bottom