Share via

Login User Table

Anonymous
2015-10-12T15:24:30+00:00

I currently use login code (see below) in the After Update property of the password field of the login form.  In my user table I have a field titled Employee Entry ID that I would like to be used in other screens and queries to limit data to only this user's data.  Is there a way to set this as an active field to be a usable variable in other queries as long as the user is logged in?

Option Compare Database

Option Explicit

Private Sub txtPassword_AfterUpdate()

'Check that User is selected

If IsNull(Me.cboUser) Then

   MsgBox "You need to select a user!", vbCritical

   Me.cboUser.SetFocus

Else

   'Check for correct password

   If Me.txtPassword = Me.cboUser.Column(2) Then

       'Check if password needs to be reset

       If Me.cboUser.Column(3) Then

           DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser

       End If

       DoCmd.OpenForm "frmMainMenu"

       Me.Visible = False

   Else

       MsgBox "Password does not match, please re-enter!", vbExclamation

       Me.txtPassword = Null

       Me.txtPassword.SetFocus

   End If

End If

End Sub

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

DBG 11,711 Reputation points Volunteer Moderator
2015-10-12T19:51:07+00:00

Hi Terry,

For #1, you got me... I actually didn't take a look at your code earlier and just noticed that you're already hiding the form by using this line:

Me.Visible = False

That hides the form and you can simply reference it by using the Forms!FormName.ControlName syntax

For #2, take a look at this Wiki article: TempVars

Hope that helps...

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. ScottGem 68,830 Reputation points Volunteer Moderator
    2015-10-20T16:50:17+00:00

    This looks like the code from my blog. If it is, my blog tells you that you can use:

    Forms!frmLogin!cboUser

    to retrieve the UserID. That's why the form is hidden so that it remains open so the control (cboUser) can be referenced anywhere in the app.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-10-20T12:16:06+00:00

    Thank you DBGuy!

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-10-12T16:51:30+00:00

    Thanks!  I do appreciate the guidance, it helps a lot by steering me in the right direction.  For option 1, keeping the login form open, what line of code would you add to the VB code listed above to keep the form open but hidden?  I know how to do this with a macro, but not sure on  the VB code.

    For option 2, do you have a sample line of code to create a temp variable?

    Thanks in advance for all your help.

    Was this answer helpful?

    0 comments No comments
  4. DBG 11,711 Reputation points Volunteer Moderator
    2015-10-12T15:53:38+00:00

    Hi. You have at least two options:

    1. Keep the login form open but hidden and use form reference in your queries, or
    2. Use TempVars to store the info so you can use it anywhere in your database.

    Just a thought...

    Was this answer helpful?

    0 comments No comments