Share via

How do I access a variable set using SetTempVar()

Anonymous
2013-04-02T17:24:48+00:00

Please pardon me if this message gets posted twice, but I tried to post it last night and now I cannot find it today.  I probably did something wrong.

I have a login form that I am attempting to store the userid value when a user logs in to my database.  I have created a form and a table to store users and their passwords.  On my form I created a macro using the SetTempVar() function on an AfterUpdate event for a text field..  I am new to Access programming and would like to see what my variables are either through debugging or by displaying a message box with the value stored in the variable.  I have struggled through with immediate windows and the value seems to be null.  I have attached some code below, but basically I want to store the value stored in my TempVar variable into a record when the AfterUpdate event occurs for all of my other forms.  Please review my code and let me know where I am going wrong or if you have any suggestions.  Thanks in advance.

Option Compare Database 'Use database order for string comparisons

Option Explicit

Dim dum As String

Private Sub cmdLogin_Click()

    dum = ProcessPassword()

End Sub

Function ProcessPassword()

Dim strWhere, strWhere2 As String

Dim varname As Variant

  If IsNull(Me.txtUserName) Or IsNull(Me.txtPassword) Then

    MsgBox "You must enter a user name and password."

  Else

   strWhere = "uCode = '" & Me.txtUserName & "' AND " & "uPassword = '" & Me.txtPassword & "'"

   varname = DLookup("[uCode] & ' ' & [uPassword]", "tblUsers", strWhere)

   Debug.Print TempVars("tmpUserID")

   If IsNull(varname) = True Then

        MsgBox "Incorrect UserName or Password, try again!", 48, "Login Error"

        Me!txtPassword = ""

        Me!txtPassword.SetFocus

    Else

      DoCmd.Close acForm, Me.Name

      DoCmd.OpenForm "frmSystemInfo"

    End If

  End If

End Function

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

  1. Anonymous
    2013-04-02T18:48:06+00:00

    I haven't used them myself. I would normally use a global variable that I set in the AfterUpdate event and use it later.

    That being said, the syntax for using temp vars in vb is:  [TempVars]![MyVar]

    I think you would use

    Debug.Print TempVars!tmpUserID

    Was this answer helpful?

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-04-02T21:13:48+00:00

    Thank you so much.  As you can see in my code I was using the wrong reference syntax.

    Was this answer helpful?

    0 comments No comments