Macro to VBA

alorenzini

Registered User.
Local time
Yesterday, 22:30
Joined
Oct 16, 2007
Messages
25
I have a bit of a quandry. I have a maco that uses SetTempVar to set the CurrentUserID so I can filter on records for that user. This is the macro:
Condition Action Arguments
Not IsNull([cboCurrentStaff]) SetTempVar CurrentUserID, [cboCurrentStaff]
Close ,,Prompt
OpenForm Home, Form, , , , Normal
StopMacro
MsgBox You must first select a staff member., Yes, None,

The specification now calls for checking for passwords and other validations. I created the following procedure:
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box

If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this matches value chosen in combo box

If Me.txtPassword.Value = DLookup("Password", "tblStaff", "[ID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value

'Close logon form and open splash screen


DoCmd.Close acForm, "Login DialogNew", acSaveNo
DoCmd.OpenForm "Home"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub

But I lose the filter for the user records when I do this. Any ideas on how to set up the SetTempVar variable in a procedure?
 
If SetTempVar was an important part of your macro why do you no longer use it in your procedure... or do you now use lngMyEmpID for the same purpose?

Brett
 

Users who are viewing this thread

Back
Top Bottom