Results 1 to 14 of 14

Thread: [RESOLVED] Log In form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Resolved [RESOLVED] Log In form

    Hi, I would like to create a login form which the user have to key in a username and password before it launch the main form. I know vb has a default form call log in dialog. But I would like to store the username and password in an access database, which the user can create in the main form after the correct first log in. Is there any examples or can anyone kind soul write a simple examples for me to refer to? Really appreciate all the help I can get!


  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Log In form

    VB Code:
    1. Sql = "Select Password From Tbl_Users Where UserName = '" & txtUserName & "'"
    2. rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
    3. If rs.EOF Then
    4.     MsgBox "No User Found in this Name !"
    5. Else
    6.     If Not rs!Password = Trim (txtPassword.Text) Then
    7.         MsgBox "Invalid Password !"
    8.     End If
    9. End If
    10. rs.Close
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Re: Log In form

    Quote Originally Posted by ganeshmoorthy
    VB Code:
    1. Sql = "Select Password From Tbl_Users Where UserName = '" & txtUserName & "'"
    2. rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
    3. If rs.EOF Then
    4.     MsgBox "No User Found in this Name !"
    5. Else
    6.     If Not rs!Password = Trim (txtPassword.Text) Then
    7.         MsgBox "Invalid Password !"
    8.     End If
    9. End If
    10. rs.Close
    Thanks for the reply! I placed these codes in the login dialog form? How about the database? Lets say if my database is data.mdb and a table called "users" and fields in "users" called "username" and "password".
    Last edited by weisi; Apr 12th, 2006 at 01:46 AM.

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Log In form

    but, make sure you are using the same fields or change the variables and field names to your requirements....and also add declarations...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Re: Log In form

    Quote Originally Posted by ganeshmoorthy
    but, make sure you are using the same fields or change the variables and field names to your requirements....and also add declarations...
    How about the adding of username and password? Im really sorry... do you mind showing me an examples?

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Log In form

    what db you are using...have you created the table in your database? is so, post the structure then i'll post the example accoring to your table structure
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Re: Log In form

    Quote Originally Posted by ganeshmoorthy
    what db you are using...have you created the table in your database? is so, post the structure then i'll post the example accoring to your table structure
    Im using access 97.

    database name = data.mdb
    table = user
    field 1 = username
    field 2 = password


  8. #8
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Log In form

    In your User Manager or something form where you want to create the users..add this code to add users to the user table
    VB Code:
    1. Dim Sql As String
    2.         Dim rsUser As ADODB.Recordset
    3.  
    4.         Set rsUser = New ADODB.Recordset
    5.         Sql = "Select * From User Where UserName='" & txtUserName.Text & "'"
    6.         rsUser.Open Sql, Cn, adOpenKeyset, adLockOptimistic
    7.         If rsUser.EOF Then
    8.             rsUser.AddNew
    9.             rsUser!UserName = Trim (txtUserName.Text)
    10.             rsUser!Password = Trim (txtPassword.Text)
    11.             rsUser.Update
    12.         Else
    13.             MsgBox "User already Exists", vbInformation, TitleMessage
    14.         End If
    15.         rsUser.Close
    16.         Set rsUser = Nothing
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Re: Log In form

    What about the login dialog? Thanks for the reply!

  10. #10
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Log In form

    create a form with 2 text boxes for user name and password and 2 command buttons for OK and Cancel...in your OK Button's click event write the code in post #2.
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    344

    Re: Log In form

    Quote Originally Posted by ganeshmoorthy
    In your User Manager or something form where you want to create the users..add this code to add users to the user table
    VB Code:
    1. Dim Sql As String
    2.         Dim rsUser As ADODB.Recordset
    3.  
    4.         Set rsUser = New ADODB.Recordset
    5.         Sql = "Select * From User Where UserName='" & txtUserName.Text & "'"
    6.         rsUser.Open Sql, Cn, adOpenKeyset, adLockOptimistic
    7.         If rsUser.EOF Then
    8.             rsUser.AddNew
    9.             rsUser!UserName = Trim (txtUserName.Text)
    10.             rsUser!Password = Trim (txtPassword.Text)
    11.             rsUser.Update
    12.         Else
    13.             MsgBox "User already Exists", vbInformation, TitleMessage
    14.         End If
    15.         rsUser.Close
    16.         Set rsUser = Nothing
    For the above mention code. Don't I have to defined tha path for my data.mdb?

  12. #12
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Log In form

    yes, you have to...when you open the db...
    VB Code:
    1. Dim Cn As ADODB.Connection
    2.     Set Cn = New ADODB.Connection
    3.  
    4.     Cn.Open "Driver=Microsoft Access Driver (*.mdb);DBQ=" & App.Path & "\Data.mdb" & ";PWD=yourDBPassword;"
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  13. #13
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: Log In form

    use a connectio string for your database path... open it like:
    VB Code:
    1. cn.open "Conn string here"

    look for connection string @ conn strings
    WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...

  14. #14
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: Log In form

    sorry just a little late
    WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...

Posting Permissions

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



Click Here to Expand Forum to Full Width