• Set combo box value as global variable (Access 2002)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Set combo box value as global variable (Access 2002)

    Author
    Topic
    #419070

    I’ve gotten so far as creating a login form based off my tblUsers. I have a combo box that displays the User Names. I need help with a few things. One, after the user selects their user name and enters a password and clicks “Ok”, I need to (1) Validate the password, and then (2) Direct them to their specific form. My train of thought is to validate the password in code, and after it passes that, use CASE to direct which form to go to, based on the User Name selected. Next, I need to set that User Name as a global variable (for use in queries/form filters). So far, I’ve created a module with this:

    Public UserName As String

    I believe somewhere amidst the onclick procedure of the “Ok” button I need code that looks like this:

    varUserName = Me.cboUserName

    help?

    Viewing 0 reply threads
    Author
    Replies
    • #945120

      It seems you’re reinventing the wheel. User-level security is a built-in feature of Access, and it will take care of checking passwords etc. automatically. Moderator WendellB has a short tutorial on his website, with useful links: The Secrets of Security.

      • #945124

        Hans,
        I would use User-Level security, and eventually I may, but I’m in need of a quick fix, and I’m designing this database with accessability in mind (read-only queries, etc..).

        Even without using this for security, I still want to use the login form to direct certain people to certain forms….and I will need to set the UserName as the variable.
        Thanks!

        • #945127

          If you use user-level security, CurrentUser is available throughout the database. (If you don’t, CurrentUser is always Admin)

          See post 198890 by Support4John for a way to set and retrieve global “variables”.

          • #945130

            Hans,
            Thanks for the info burga When I set that variable through “OnClick” on my login form and then my login form closes, does that value remain until the database is opened again?

            • #945133

              The value remains as long as the database is open, but not if the database as a whole is closed and reopened. The user will have to login again.

            • #945137

              Awesome. Thank you Hans. Now I’m off to find out how to validate my pw.
              Thanks

            • #945151

              So I go through the Login form and everything, and when I try to do something that works off of the query that filters for just that user’s company, I get the error :

              Undefined functin ‘username’ in expression

              The criteria in my query for company =
              DLookUp(“Company”,”tblUsers”,”UserName=” & Chr(34) & UserName() & Chr(34))

            • #945156

              I get the impression we’re discussing the same subject in two threads at once now. Can I lock one of them, and if so, which one?

            • #945168

              We are, you’re right. Lock whichever…I believe this one is more pertinent…so g’head and lock the other one..here’s my last post from it:

              ——————————————————————————–
              (this assumes that you have applied user-level security with the usernames and passwords from the table)
              ——————————————————————————–

              So I completely missed that. Now that we know I haven’t any user level security applied….where do we go from there? (I realize the obvious way would be to apply user level security…that’s something I’ve yet to meddle in, I’ve secured my database well enough to keep honest people honest so far, and it’s worked…)

            • #945196

              I agree with Hans – it appears to me you’ve spent several hours trying to solve a problem that Access User Security solves. And it only takes about 10 minutes to apply the feature – you start by giving the Admin user a password. To really secure it to the point where it requires a hacker to break into it is more complicated, but even that only takes a couple of hours at the most. If it looks like a wheel, acts like a wheel, and meets your needs, then it must be a wheel.

    Viewing 0 reply threads
    Reply To: Set combo box value as global variable (Access 2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: