We help IT Professionals succeed at work.
Get Started

Global Variable Disapearance in Access VBA Errors

189 Views
Last Modified: 2016-02-11
Hi All,

Hoping someone can help me here but here goes.

In a standard module named bas_autos, I have declared the following global variables.

Option Compare Database
Option Explicit
Global APPUser          As String
Global APPUserID        As Long
Global APPUserEmail     As String
Global AppUserType      As Integer
Global AppEntID         As Integer
Global HWFingerPrint    As String

Open in new window


When my database opens, I have a userform (frm_login) that is displayed by default. All users MUST use this form to login to the database.

In doing so, I use the following code to collect those global variables at the time of successfully logging into the database.

'check temp pin and direct to change passcode ->
            If vTempPin = True Then
                
                APPUser = Nz(Me.cboUserName.Column(1), "")
                APPUserID = Nz(Me.cboUserName.Column(0), "")
                AppUserType = Nz(Me.cboUserName.Column(6), "")
                APPUserEmail = Nz(Me.cboUserName.Column(8), "")
                AppEntID = Nz(Me.cboEntity.Column(0), "")
                HWFingerPrint = CurrentMachineName
                
                DoCmd.Close 2, "frm_login"
                DoCmd.OpenForm "frm_user_pin"
                
                'use the settings for the user to acces and update their password ->
                Forms("frm_user_pin").Controls("txtOldPW").Value = vTempPin
                Forms("frm_user_pin").Controls("lblPin").Caption = "Change Pin"
                Forms("frm_user_pin").Controls("cmdCancel").Visible = False
                Forms("frm_user_pin").Controls("txtNewPW").SetFocus
                
                msg = "Please change your user pin by entering a new 4-digit pin that you have not used previously."
                title = "New pin required"
                style = vbOKOnly + vbInformation
                response = MsgBox(msg, style, title)
                Forms("frm_user_pin").Repaint
            Else
                'everything is fine just go straight to dashboard ready for session ->
                APPUser = Nz(Me.cboUserName.Column(1), "")
                APPUserID = Nz(Me.cboUserName.Column(0), "")
                AppUserType = Nz(Me.cboUserName.Column(6), "")
                APPUserEmail = Nz(Me.cboUserName.Column(8), "")
                AppEntID = Nz(Me.cboEntity.Column(0), "")
                HWFingerPrint = CurrentMachineName
                
                'access is okay then update current username and store global variable ->
                DoCmd.Close 2, "frm_login"
                DoCmd.OpenForm "frm_dashboard"
                
                'repaint the form ->
                Forms("frm_dashboard").Repaint
            End If

Open in new window


My problem is that if the application errors in ANY way, I keep losing these global variables that were collected at the beginning of a session.

Is there any way to circumvent this problem or am I completely missing something ?

Thanks,
Lai
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This problem has been solved!
Unlock 2 Answers and 12 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE