How can I store a person's username, to then be used in any form in the program?

105ben

Registered User.
Local time
Today, 16:42
Joined
Feb 2, 2013
Messages
42
Basically, once the user logs in I'd like my system to store their username so it can then be used in other places, without the user needing to re-enter it.

How can I do this?
 
Hello 105ben, so are you using a login form to collect the user name? If so instead of closing the form after authenticating, just make the form invisible so you can use the value from the form later..
 
Also you can make use of a VBA class to store data. To make the instance of the class Global to your entire program, in a VBA module at the very top before Functions / Subroutines, there create the instance of the class. Example:

Code:
Option Compare Database
Option Explicit

'Order of creation of these objects should be the same order they are used in
'Form_main \ Form_Load()
[B]Public ObjAppSettings As New clsObjAppSettings[/B]
Public ObjBEDBConnection As New clsObjBEDBConnection
Public ObjAuthTbl As New clsObjAuthTbl
Public ObjMSysObjectsTbl As New clsObjMSysObjectsTbl
Then you will be able to access that object anywhere in the program. Example:

Code:
  Dim strMSysObjectsConnectString As String

  'Fetch the correct ConnectString based on this workstation's configuration settings
  strMSysObjectsConnectString = [B]ObjAppSettings.MSysObjectsConnectString()[/B]
 
They are choosing it from a drop down menu, would this still work?
 
Sorry mdluleck! thanks for your reply, im going to try the other method first as it seems a bit simpler

How do I make the form not visible?

frmLogin.visible = false

doesnt seem to work?
 
In the very last step while authenticating the user using the Login Form, you would have the code something like..
Code:
Private logMeInBtn_Click()
   [COLOR=Green] 'code to check the user validity[/COLOR]
    Me.Visible = False
    [COLOR=Green]'code to open the appropriate Forms[/COLOR]
End Sub
The above code is a sample, considering that the user would click a button to perform the login action...
 
Have a login form right at the begging of the DB so users must go to this and enter their username before they can go elsewhere.

When they progress from thism you can either minimize the login form or just hide it - either way leave it open. You can then do one of two things:

On any form where you need to have the login name, just add a field which looks up the value from your login form ( [Forms]![Frm_Login]![Username] and it will pull it through.

Alternatively you can use a Dlookup - can supply code if needs be.
 

Users who are viewing this thread

Back
Top Bottom