Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004

    Question Unanswered: Storing the result of a query in a global variable

    Hi, i need help (figures why i'm here right..). I'm trying to store the result of a query in a global variable, but i don't know how to do this, so could you look at this code and point me in the right direction ?


    Option Compare Database
    'Global Vairables
    Dim gstrUserLevel As String
    'gstrUserLevel stores the user's level of access
    Public Sub Login()
    'This procedure logins the user, checks the user level and takes them to the appropriate forms
    'and reports.
    Dim pstrUserID As String
    Dim pstrUserPass As String
    Dim pintAccess As Integer
    'pstrUserID = Forms![frmSwitchboard]![txtUserID]
    pstrUserID = "User"
    'pstrUserPass = Forms![frmSwitchboard]![txtPassword]
    pstrUserPass = "user"
    'create a connection object
    Dim cnn As ADODB.Connection
    Dim cmd As New ADODB.Command
    Dim plngRecordsAffected As Long
    Set cnn = CurrentProject.Connection
    cmd.ActiveConnection = cnn
    cmd.CommandText = "qryLoginUser"
    cmd.Execute plngRecordsAffected, Array(pstrUserID, pstrUserPass)
    'debugging purposes
    MsgBox plngRecordsAffected
    the query results in 'Admin' but i want to store this result in a variable gstrUserLevel.

    If someone can help me before April 30th, i'd be really happy


  2. #2
    Join Date
    Feb 2004
    Use this at the top of your code, it will become global or public.

    Option Compare Database
    Option Explicit
    Public gstrUserLevel As String

    Then get rid of your dim w/ gstrUserLevel .
    You do not give enough info to determine where/how 'Admin' is used.

  3. #3
    Join Date
    Apr 2004


    Thanx . I'm sorry about that, didn't think it was necessary. Admin is one of four access levels stored for a user: Admin,Tech,Accts,Ags. The goal is to store the access level from the query, which has the parametes userid and userpass then only allow them to access specific forms based on their access level.

    the code which follows goes kind of like this:

    If gstrUserLevel = "Admin" Then
    MsgBox "Logged in As " & gstrUserLevel
    DoCmd.GoToPage 2
    so on and so forth

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts