login table and login form

Discussion in 'Microsoft Access Form Coding' started by kennytwk, Dec 7, 2006.

  1. kennytwk

    kennytwk Guest

    hi i'm new here

    i have a login table with user name and password, and a form that require
    a username and password to trigger another form, i have connected my form to
    the table, can anyone tell me how do i make my form and table work the way we
    log in into this forum?? thanks, i know how to do it in java but i'm new to
    vba in access
     
    kennytwk, Dec 7, 2006
    #1
    1. Advertisements

  2. kennytwk

    Damon Heron Guest

    If I understand correctly, you want the login form to come up when the db is
    opened? Select Tools, Startup, and put the name of the form where it says
    Display form/page.

    HTH
    Damon

    "kennytwk" <u30020@uwe> wrote in message news:6a68d8a8b611a@uwe...
    > hi i'm new here
    >
    > i have a login table with user name and password, and a form that require
    > a username and password to trigger another form, i have connected my form
    > to
    > the table, can anyone tell me how do i make my form and table work the way
    > we
    > log in into this forum?? thanks, i know how to do it in java but i'm new
    > to
    > vba in access
    >
     
    Damon Heron, Dec 7, 2006
    #2
    1. Advertisements

  3. no :), i'm to build a login feature to my access application, i need my form
    to verify the table and authenticate then user. if valid another form will
    prompt out.

    --
    Message posted via http://www.accessmonster.com
     
    kennytwk via AccessMonster.com, Dec 8, 2006
    #3
  4. kennytwk

    Damon Heron Guest

    Explain what you mean by "verify the table"? When you open the form, you
    can have a combobox for user name and textbox for password that is stored in
    the table. The combobox has a row source tied to the table - "SELECT
    tblUser.UserID, tblUser.UserName, tblUser.EncryptedPassword FROM tblUser
    ORDER BY tblUser.UserName;"

    The form's code is like this:

    Private Sub cmdChkPwd_Click() ' this is a command button click event that is
    on the form
    If Me.txtPwd = Me.cboLogin.Column(2) Then ' textbox for password and
    combobox for username
    DoCmd.Close acForm, "frmLogon" 'this is the login form
    DoCmd.openform "frmSplash" ' this is the form that will open after
    successful logon

    Else
    If ct < 4 Then 'this gives four chances
    MsgBox "Password not recognized. Try again!", vbOKOnly, "WineWorks"
    ct = ct + 1
    Else
    DoCmd.Quit
    End If
    End If
    End Sub

    In the form's module, you need:
    Option Compare Database
    Dim ct As Integer ' this is the counter for the number of logon attempts.
    ***************

    This is really light security. If you need more security, then consider
    workgroups, or sql server. The above code can be fairly secure if you
    disable the bypass key and make an mde file, though.

    HTH
    Damon


    "kennytwk via AccessMonster.com" <u30020@uwe> wrote in message
    news:6a6f4aa4c5467@uwe...
    > no :), i'm to build a login feature to my access application, i need my
    > form
    > to verify the table and authenticate then user. if valid another form will
    > prompt out.
    >
    > --
    > Message posted via http://www.accessmonster.com
    >
     
    Damon Heron, Dec 8, 2006
    #4
  5. Thanks, what i mean is i have 2 text box,
    the first 1 is for the user to key in the username, the second is for the
    password, for normal authentication, it act like the way we log into hotmail
    or this forum, i have a table, each records have a username and password, if
    the record match to the one that the user key into the text boxs, access is
    valid, else invalid access to my system,

    i think i get what u mean, i have been going through some books to connect
    database with ADO, i will try first on my own, thanks, ur code gave me some
    idea though :)

    btw about the may i know what u mean by workgroups? is it some setting in MS
    Access?,

    i have another authentication process where "many user to one ID and
    password", which mean multiple user will be using the same "username and
    password" to login to an application at the same time, those user can only
    "view" whatever that is available in the application, no updating or editing
    priviledge is given to them. is it using the "same module" as the 1 above?
    can anyone give me some idea? thanks.

    --
    Message posted via AccessMonster.com
    http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200612/1
     
    kennytwk via AccessMonster.com, Dec 11, 2006
    #5
  6. kennytwk

    Damon Heron Guest

    Type "Workgroups" in Access Help. you'll get lots of information on
    security there. It's not for the faint of heart though. Make sure you
    thoroughly understand it before implementing it.

    Damon

    "kennytwk via AccessMonster.com" <u30020@uwe> wrote in message
    news:6a9b8956d2a47@uwe...
    > Thanks, what i mean is i have 2 text box,
    > the first 1 is for the user to key in the username, the second is for the
    > password, for normal authentication, it act like the way we log into
    > hotmail
    > or this forum, i have a table, each records have a username and password,
    > if
    > the record match to the one that the user key into the text boxs, access
    > is
    > valid, else invalid access to my system,
    >
    > i think i get what u mean, i have been going through some books to connect
    > database with ADO, i will try first on my own, thanks, ur code gave me
    > some
    > idea though :)
    >
    > btw about the may i know what u mean by workgroups? is it some setting in
    > MS
    > Access?,
    >
    > i have another authentication process where "many user to one ID and
    > password", which mean multiple user will be using the same "username and
    > password" to login to an application at the same time, those user can only
    > "view" whatever that is available in the application, no updating or
    > editing
    > priviledge is given to them. is it using the "same module" as the 1 above?
    > can anyone give me some idea? thanks.
    >
    > --
    > Message posted via AccessMonster.com
    > http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200612/1
    >
     
    Damon Heron, Dec 12, 2006
    #6
  7. Hi, can anyone tell me where me where i went wrong?, i'm new to vba, the code
    may look terrible to u guys, thanks, i have a table "Login" with 2 field
    "Username, Password". Another 2 text box, Text0_Username and Text2_Password.

    Private Sub Command5_Click()
    On Error GoTo Err_Command5_Click

    Dim ct As Integer
    Dim cmd5 As ADODB.Command
    Dim rst1 As ADODB.Recordset
    Dim str1 As String
    Dim fld1 As ADODB.Field
    Dim stDocName As String
    Dim stLinkCriteria As String

    Set cmd5 = New ADODB.Command
    With cmd5
    .ActiveConnection = CurrentProject.Connection
    .CommandText = "SELECT Username, Password FROM LOGIN"
    .CommandType = adCmdText
    End With

    Set rst1 = cmd5.Execute
    Do Until rst1.EOF
    str1 = ""
    For Each fld1 In rst1.Fields
    str1 = str1 & fld1.Value & vbTab
    Next fld1
    rst1.MoveNext
    Loop



    If (Text0 = fld1 & Text2 = fld1) Then
    stDocName = "Project"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Else
    If ct < 4 Then
    MsgBox "Password not recognized. Please Try again!", vbOKOnly
    ct = ct + 1
    Else
    DoCmd.Quit
    End If
    End If

    rst1.Close
    Set fld1 = Nothing
    Set rst1 = Nothing
    Set cmd5 = Nothing

    Exit_Command5_Click:
    Exit Sub


    Err_Command5_Click:
    MsgBox Err.Description
    Resume Exit_Command5_Click

    End Sub

    --
    Message posted via AccessMonster.com
    http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200612/1
     
    kennytwk via AccessMonster.com, Dec 12, 2006
    #7
  8. kennytwk

    Damon Heron Guest

    You are making it way too difficult.

    First the table -I would have three fields: UserID, UserName, Password.
    (UserID is an autonumber as primary key). Password field has an input mask
    of "Password". This hides the actual password from prying eyes.
    Now the form - why have users type in their name each time? Make the User
    textbox a combobox instead, and

    set the row source (in Properties) to the following: SELECT Login.UserID,
    Login.UserName, Login.Password FROM Login ORDER BY Login.UserName;

    Then set the combobox format properties:
    ColumnCount to 3,
    ColumnWidths to 0";1";0" (this stores the values UserID, name and Password,
    but only shows the UserName. So combobox1.column(0) is the UserID,
    column(1) is the name, and column(2) is the password.

    Finally set the input mask of the textbox to "Password" so what the user
    types doesn't show on the screen.

    Now the user types in the password in text2, and the command button, when
    clicked, checks the textbox against combobox.column(2), and if they match
    entry is allowed.
    So the command button code is only this: (note that I give them more
    descriptive names: your text2 is txtPwd, combobox is cboLogin)

    Private Sub Command5_Click() ' left off error check for brevity
    If Me.txtPwd = Me.cboLogin.Column(2) Then
    curUser = Me.cboLogin.Column(0)
    DoCmd.Close acForm, "LogonForm"
    DoCmd.openform "Your Project Form"
    Else
    If ct < 4 Then
    MsgBox "Password not recognized. Try again!", vbOKOnly, "My Project"
    ct = ct + 1
    Else
    DoCmd.Quit
    End If
    End If
    End Sub

    Note also the the "ct" variable is not is this click event! Assign the
    variable at the form level, up where it says "Option Compare Database" - the
    reason is if it was inside the click event it would never reach 4 since each
    click would re-initialise it to zero.

    Damon



    "kennytwk via AccessMonster.com" <u30020@uwe> wrote in message
    news:6aa1ee3a926fa@uwe...
    > Hi, can anyone tell me where me where i went wrong?, i'm new to vba, the
    > code
    > may look terrible to u guys, thanks, i have a table "Login" with 2 field
    > "Username, Password". Another 2 text box, Text0_Username and
    > Text2_Password.
    >
    > Private Sub Command5_Click()
    > On Error GoTo Err_Command5_Click
    >
    > Dim ct As Integer
    > Dim cmd5 As ADODB.Command
    > Dim rst1 As ADODB.Recordset
    > Dim str1 As String
    > Dim fld1 As ADODB.Field
    > Dim stDocName As String
    > Dim stLinkCriteria As String
    >
    > Set cmd5 = New ADODB.Command
    > With cmd5
    > .ActiveConnection = CurrentProject.Connection
    > .CommandText = "SELECT Username, Password FROM LOGIN"
    > .CommandType = adCmdText
    > End With
    >
    > Set rst1 = cmd5.Execute
    > Do Until rst1.EOF
    > str1 = ""
    > For Each fld1 In rst1.Fields
    > str1 = str1 & fld1.Value & vbTab
    > Next fld1
    > rst1.MoveNext
    > Loop
    >
    >
    >
    > If (Text0 = fld1 & Text2 = fld1) Then
    > stDocName = "Project"
    > DoCmd.OpenForm stDocName, , , stLinkCriteria
    > Else
    > If ct < 4 Then
    > MsgBox "Password not recognized. Please Try again!", vbOKOnly
    > ct = ct + 1
    > Else
    > DoCmd.Quit
    > End If
    > End If
    >
    > rst1.Close
    > Set fld1 = Nothing
    > Set rst1 = Nothing
    > Set cmd5 = Nothing
    >
    > Exit_Command5_Click:
    > Exit Sub
    >
    >
    > Err_Command5_Click:
    > MsgBox Err.Description
    > Resume Exit_Command5_Click
    >
    > End Sub
    >
    > --
    > Message posted via AccessMonster.com
    > http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200612/1
    >
     
    Damon Heron, Dec 12, 2006
    #8
  9. kennytwk via AccessMonster.com, Dec 13, 2006
    #9
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lee T.

    Contdionally open a form based on a form and a table

    Lee T., Sep 10, 2003, in forum: Microsoft Access Form Coding
    Replies:
    4
    Views:
    148
    Alick [MSFT]
    Sep 15, 2003
  2. Les
    Replies:
    0
    Views:
    191
  3. Jay
    Replies:
    1
    Views:
    202
    Graham Mandeno
    May 21, 2004
  4. Form/Table Problem (form doesn't input info into table)

    , Mar 25, 2008, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    215
    John W. Vinson
    Mar 25, 2008
  5. Jeanette Cunningham

    Re: Temporary Form with 2 Sub form Update Main Form And its Sub form ?

    Jeanette Cunningham, Nov 25, 2009, in forum: Microsoft Access Form Coding
    Replies:
    0
    Views:
    574
    Jeanette Cunningham
    Nov 25, 2009
Loading...

Share This Page