-
Apr 12th, 2006, 01:17 AM
#1
Thread Starter
Hyperactive Member
[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!
-
Apr 12th, 2006, 01:39 AM
#2
Re: Log In form
VB Code:
Sql = "Select Password From Tbl_Users Where UserName = '" & txtUserName & "'"
rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
If rs.EOF Then
MsgBox "No User Found in this Name !"
Else
If Not rs!Password = Trim (txtPassword.Text) Then
MsgBox "Invalid Password !"
End If
End If
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.
-
Apr 12th, 2006, 01:42 AM
#3
Thread Starter
Hyperactive Member
Re: Log In form
Originally Posted by ganeshmoorthy
VB Code:
Sql = "Select Password From Tbl_Users Where UserName = '" & txtUserName & "'"
rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
If rs.EOF Then
MsgBox "No User Found in this Name !"
Else
If Not rs!Password = Trim (txtPassword.Text) Then
MsgBox "Invalid Password !"
End If
End If
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.
-
Apr 12th, 2006, 01:45 AM
#4
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.
-
Apr 12th, 2006, 01:48 AM
#5
Thread Starter
Hyperactive Member
Re: Log In form
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?
-
Apr 12th, 2006, 02:00 AM
#6
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.
-
Apr 12th, 2006, 02:07 AM
#7
Thread Starter
Hyperactive Member
Re: Log In form
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
-
Apr 12th, 2006, 02:17 AM
#8
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:
Dim Sql As String
Dim rsUser As ADODB.Recordset
Set rsUser = New ADODB.Recordset
Sql = "Select * From User Where UserName='" & txtUserName.Text & "'"
rsUser.Open Sql, Cn, adOpenKeyset, adLockOptimistic
If rsUser.EOF Then
rsUser.AddNew
rsUser!UserName = Trim (txtUserName.Text)
rsUser!Password = Trim (txtPassword.Text)
rsUser.Update
Else
MsgBox "User already Exists", vbInformation, TitleMessage
End If
rsUser.Close
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.
-
Apr 12th, 2006, 02:33 AM
#9
Thread Starter
Hyperactive Member
Re: Log In form
What about the login dialog? Thanks for the reply!
-
Apr 12th, 2006, 02:37 AM
#10
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.
-
Apr 12th, 2006, 02:43 AM
#11
Thread Starter
Hyperactive Member
Re: Log In form
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:
Dim Sql As String
Dim rsUser As ADODB.Recordset
Set rsUser = New ADODB.Recordset
Sql = "Select * From User Where UserName='" & txtUserName.Text & "'"
rsUser.Open Sql, Cn, adOpenKeyset, adLockOptimistic
If rsUser.EOF Then
rsUser.AddNew
rsUser!UserName = Trim (txtUserName.Text)
rsUser!Password = Trim (txtPassword.Text)
rsUser.Update
Else
MsgBox "User already Exists", vbInformation, TitleMessage
End If
rsUser.Close
Set rsUser = Nothing
For the above mention code. Don't I have to defined tha path for my data.mdb?
-
Apr 12th, 2006, 03:12 AM
#12
Re: Log In form
yes, you have to...when you open the db...
VB Code:
Dim Cn As ADODB.Connection
Set Cn = New ADODB.Connection
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.
-
Apr 12th, 2006, 03:14 AM
#13
Fanatic Member
Re: Log In form
use a connectio string for your database path... open it like:
VB Code:
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...
-
Apr 12th, 2006, 03:14 AM
#14
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|