Results 1 to 13 of 13
  1. #1
    Join Date
    May 2002
    Posts
    20

    Unanswered: dlookup for login form

    I am new in access but I have to do a login form with 2 textboxs and a button to login. My boss sayed that I have to use the dlookup function do get the username and the password from the 2 colums of the table. It works good but it only finds the first record of the table..
    please... help me.
    Thanks in advance

    here's the code for the button:

    Private Sub Comando5_Click()
    Dim stDocName As String
    Dim Msg, Style, Title, Response, MyString
    Dim nome_login As Variant
    Dim pass_login As Variant


    stDocName = "Listagem"
    nome_login = DLookup("[nome]", "login", "")
    pass_login = DLookup("[password]", "login", "")
    Msg_nome = "nome errado"
    Msg_pass = "password errada"
    Style = vbOKOnly + vbExclamation + vbSystemModal
    Title = "falha de segurança"

    If [nome] = nome_login And [password] = pass_login Then
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    ElseIf [nome] <> nome_login Then
    Response = MsgBox(Msg_nome, Style, Title)
    ElseIf [password] <> pass_login Then
    Response = MsgBox(Msg_pass, Style, Title)
    End If

    End Sub


    p.s - sorry for my poor inglish #)

  2. #2
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    hey fallen,

    Here is an attachment of database I posted a while back with an example of a login form. You may want to consider changing your procedure. Let me know what you think.

    User= John
    Password = password


    Later, Kal
    Attached Files Attached Files

  3. #3
    Join Date
    May 2002
    Posts
    20

    thanks

    thanks a lot!!!! you really really aved me #)
    I only ude access for about 2 weeks.. and the only programming language that I used was delphi and a little of C.. besides that.. i am young.. lol

    Excellent code you have there many thanks

  4. #4
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    Happy to help!!

  5. #5
    Join Date
    Aug 2010
    Posts
    4

    Access Login Form Dlookup help

    I am trying to use a DLookup but am not having any luck. I am creating a login form and I am sure it is riddled with errors but here is my code and I included my database too. Any help would be greatly appreciated.


    Private Sub btnLogin_Click()

    Dim strAccessLevel As String
    Dim tblLogin As String

    'strAccessLevel = DLookup("[strAccess]", "tblLogin", "[strlogin] = '" & Me.txtusername & "'")

    'Select Case strAccessLevel
    'Case 1
    'strForm = "frmMaster"

    'Case 2
    'strForm = "frmChangePassword"

    'End Select

    DoCmd.OpenForm "frmLogin2"

    'Check to see if data is entered into the UserName combo box

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

    'Check value of Username in tblLogin to see if this matches value chosen in text box

    If DLookup("Username", "tblLogin", "[Username]= " & Me.txtusername) Then

    Login = OpenForm.Master

    '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 tblLogin to see if this matches value chosen in text box

    If DLookup("Password", "tblLogin", "[Password]= " & Me.txtPassword) Then

    Login = Me.txtusername.Value

    'Checks password value for default

    If Me.txtPassword.Value = "password" Then
    DoCmd.OpenForm "frmChangePassword"
    Else

    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




    'Open Master screen

    DoCmd.OpenForm "frmMaster"

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

    'Checks user type and opens appropriate form






    End Sub
    Attached Files Attached Files

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what errors are you getting
    what efforts have you made to diagnose what is going wrong
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Aug 2010
    Posts
    4
    It says Run time Error 2471:

    The expression you entered as a query parameter produced this error : 'rhamilton'

    It then highlights my DLookup:

    If DLookup("Username", "tblLogin", "[Username]= " & Me.txtusername) Then

    Login = OpenForm.Master

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

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    as its a text field I suspect its whinging about the lackof ' or " used to denote a text value
    If DLookup("Username", "tblLogin", "[Username]= '" & Me.txtusername &"'" &""") Then


    mind you I still thinks its daft to write your own logon screen when effectivley you can use the network logon... see the code bank for details or google dev ashish api
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Aug 2010
    Posts
    4
    Oh....Yeah that would be way easier.....THANKS!!!!!

  10. #10
    Join Date
    Aug 2010
    Posts
    4
    Hey Healdem, That did work freakin awesome so thank you again. I was curious though and I was googling to see but didn't find anything. I still want the user to enter a password to not allow some passerby from just bringing it up, is there a similar code that will verify the network password?

  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I know of no way a VBA program can access the network password or logon functions. it may be possible to force a network sign off. whenever I have encountered this sort of issue in the past we have used a very low timeout on the network logon sessions and also made it a disciplinary to leave your computer logged on whilst you are away from it
    I'd rather be riding on the Tiger 800 or the Norton

  12. #12
    Join Date
    Jun 2016
    Posts
    1

    login file

    the file won't open with the given user and password John password


    Quote Originally Posted by kpalmer View Post
    hey fallen,

    Here is an attachment of database I posted a while back with an example of a login form. You may want to consider changing your procedure. Let me know what you think.

    User= John
    Password = password


    Later, Kal

  13. #13
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    check you are using the supplied credentials
    ..it works fine here
    noth are case insensitive so if you are not able to open the db its a problem at your end
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •