RE: Macro to VBA

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
.



Relevant Pages

  • Re: Date range on reports
    ... > box to your report with a control source like: ... >> In the Database window (Database window: The window that appears when you ... >> In the New Form dialog box, click Design View, and click OK. ... >> Begin by clicking Macro Names to display the Macro Name column. ...
    (microsoft.public.access.reports)
  • Re: Newbies first image: BSOD 0x7B
    ... Having all the components mentioned in the macro platform component would be ... > - add this component to the database using the Component Database Manager, ... > Info:Creating: LSI Logic FC909 Fibre Channel Adapter ...
    (microsoft.public.windowsxp.embedded)
  • RE: Manipulating MS Access records with excel VBA + ADO
    ... and other SQL filters into the code. ... Then in the 1st macro ... You have the choice of searching through the database by making a SQL to ... ' Macro recorded 1/19/2009 by Joel ...
    (microsoft.public.excel.programming)
  • Re: Combine Multiple tables into One Master table
    ... You can use a macro with 3 TransferText actions, one for each table, to get the data imported into your Access tables. ... the Open event of a form which always opens when the database opens - but then what if today's import has already been done. ... And then make an Update Query to add the data to the other fields from the related records in the other two import tables. ...
    (microsoft.public.access.macros)
  • [Info-ingres] FW: Ingres DBA/Developer opportunity
    ... DATABASE ADMINISTRATOR - DBA AND DEVELOPER ... Extensive working knowledge of current programming, ... documentation and reports. ...
    (comp.databases.ingres)