RE: Macro to VBA
- From: dbalorenzini <dbalorenzini@xxxxxxxx>
- Date: Mon, 12 Jan 2009 07:22:07 -0800
Could you help me write this as a function? Is it as simple as changing my
reference to my controls (Me.cboEmployee and Me.txtPassword) to reference
sUSer and sPass?
Public Function udf_Login(sUser, sPass)
'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 Function
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 Function
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 Dialog", 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 Function
--
Thanks,
Art
Database Administrator
Yankton, SD
"Dymondjack" wrote:
I not sure about doing that in a macro, I don't generally use them. If I had.
to run a login procedure off a macro I would just make a function to call
from the macro that does the checks and opens the form if everything passes.
in the macro:
RunCode
=fLogin(Me.ctlUser, Me.ctlPass)
and the function:
Public Function fLogin(sUser, sPass)
'check that the user exists
'make sure user isnt already logged on
'verify password
'open frmHome and close frmLogin
End Function
As far as the TempVars I'm not really sure, I don't have any experience with
them (they're new to 07 i think? i'm on 03), but I run an Active Users table.
A record of the user, computer and the winuser are logged from fLogin and
fLogout on my frmHome_Close event removes the entry (and other cleanup..).
This might be a little off leauge with what you were looking, I wouldn't
know how to handle it with a macro, but I just got done wrapping up a solid
login/out procedure about a month ago and that worked out well for me.
"dbalorenzini" wrote:
Not sure how to approach that. Woould there be a way to do the password
validation within the Macro?
--
Thanks,
Art
Database Administrator
Yankton, SD
"Dymondjack" wrote:
Taken from:
http://office.microsoft.com/en-us/access/HA101202161033.aspx
Temporary variables are global. Once a temporary variable has been created,
you can refer to it in an event procedure (event procedure: A procedure that
is automatically executed in response to an event initiated by the user or
program code, or that is triggered by the system.), a Visual Basic for
Applications (VBA) (Visual Basic for Applications (VBA): A macro-language
version of Microsoft Visual Basic that is used to program Microsoft
Windows-based applications and is included with several Microsoft programs.)
module, a query, or an expression. For example, if you created a temporary
variable named MyVar, you could use the variable as the control source for a
text box by using the following syntax:
=[TempVars]![MyVar]
On a side note, in case you weren't aware, your password verification is not
case sensitive
Me.txtPassword.Value = DLookup("Password", "tblStaff", "[ID]=" &
Me.cboEmployee.Value)
Will return true regardless of case. Maybe you're fine with this, but if
you do want case sensitive, I use the following:
If (Instr(1, <StoredPass>, <UserInputPass>, vbBinaryCompare) = 1) And _
(Len(<StoredPass>) = Len(<UserInputPass>)) Then
'Password Verification OK
End If
HTH
-jack
"dbalorenzini" wrote:
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?
--
Thanks,
Art
Database Administrator
Yankton, SD
- Follow-Ups:
- RE: Macro to VBA
- From: Dymondjack
- RE: Macro to VBA
- References:
- Macro to VBA
- From: dbalorenzini
- RE: Macro to VBA
- From: Dymondjack
- RE: Macro to VBA
- From: dbalorenzini
- RE: Macro to VBA
- From: Dymondjack
- Macro to VBA
- Prev by Date: Re: Changing query criteria through VBA
- Next by Date: Re: Changing query criteria through VBA
- Previous by thread: RE: Macro to VBA
- Next by thread: RE: Macro to VBA
- Index(es):
Relevant Pages
|