Please could some one provide me the code to validate the user name and password fields using Vb for MS access.
Fields ::
User name :: text box
Password :: text box
Login :: button
The form should accept the user name and password from the text box , validate the same against a table on MS access if successful should allow the user to proceed to next form else display a alert/error message.
Thanks a lot,
Mithun.
14 7337
Kindly post the code that you have tried to solve this problem, to get help from our experts
Code containing errors - Private Sub Login1_Click()
-
On Error GoTo Err_Login1_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
text3.SetFocus
-
-
If text3.Text = user_validate.user_name And text5.Text = user_validate.Password Then
-
-
stDocName = "Applications"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
Else
-
MsgBox "Please enter correct user name and password", vbOKOnly
-
-
-
Exit_Login1_Click:
-
Exit Sub
-
-
Err_Login1_Click:
-
MsgBox Err.Description
-
Resume Exit_Login1_Click
-
End If
-
End Sub
Hi,
Remove the error handling and keep a break point and tell us which line u r getting the error...?
What is this :
user_validate.user_name
(TableName.FieldName) or (FormName.ControlName)... ?
REgards
Veena
how secure are you wanting this to be you may want to consider some encrytion as the password and username can easly be retrived by a hex editor this way
Hi,
Remove the error handling and keep a break point and tell us which line u r getting the error...?
What is this :
user_validate.user_name
(TableName.FieldName) or (FormName.ControlName)... ?
REgards
Veena
user_validate.user_name
(TableName.FieldName)
Hi,
Then, u simply cant give, TableName.FieldName,
U have to declare a Record set Open Recordset with the "Where Crieteria", if u find any Records, then allow to proceed or else, Prompt again, giving appropriate message . SQL Statement shud be something like this : -
sSQL = "Select * From UserTable Where UserName = '" & TxtUserName.Text & "' And Password = '" & txtpwd.text & "'"
-
Regards
Veena
Trying with the following code....
getting an error as "Object required"
* * * code * * * - Private Sub Login_Click()
-
On Error GoTo Err_Login_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
Dim user_name As String
-
Dim passwor As String
-
-
-
If user_validate.user_name = Text3.Text And user_validate.Password = Text5.Text Then
-
sSQL = "Select * From User_validate Where User_Name = '" & Text3.Text & "' And Password = '" & Text5.Text & "'"
-
-
stDocName = "Applications"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Else
-
MsgBox "Invalid user id or password, please try again", vbOKOnly
-
-
-
-
Exit_Login_Click:
-
Exit Sub
-
-
Err_Login_Click:
-
MsgBox Err.Description
-
Resume Exit_Login_Click
-
End If
-
-
End Sub
Hi Mithun,
Open a Recordset with the given SQL Statement, in ur code, open recordset line is missing..
REgards
Veena
Hi Mithun,
Open a Recordset with the given SQL Statement, in ur code, open recordset line is missing..
REgards
Veena
Hi Veena,
I'm a begineer with VB. Please could you let me know how i can Open a Recordset with the given SQL Statement.
Thanks a lot for the guidance and support.
regards,
Mithun
Hi,
I have not used mucg of VBA, I always work on VB6,
Anyway, Check This Basic Code:
I assume u r using ADO -
Dim rs As ADODB.Recordset
-
Dim sSQL As String
-
Set rs = New ADODB.Recordset
-
sSQL ="Select * From MyUserTable Where UserName = '" _
-
& Trim(txtUserName.Text) & "' And Pwd ='" & Trim(txtPwd.Text) & "'"
-
rs.Open sSQL, CurrentProject.Connection
-
If RS.EOF Then
-
Msgbox "User Not Found"
-
'Prompt again for user name /pwd
-
Else
-
'User Found
-
'Write Code to Open ur Application
-
End If
-
rs.Close
-
Set rs = Nothing
-
-
U can refine the Code..
REgards
Veena
Hi Veena,
Thanks a lot for the help and guidance.....
I have a question with regards to setting the focus on an object "
Please could you let me know whether I can explicitly set focus on more than one object at a time. i.e., user name and password fields"
Thanks and regards,
Mithun
The following code is working fine... except for
.... it is requesting me to set the focus on the text box (Password) field too....
Please could you let me know whether I can explicitly set focus on more than one object at a time.if so how?
Private Sub Login_Click()
On Error GoTo Err_Login_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim user_name As String
Dim password As String
Dim temp As String
Dim rs As ADODB.Recordset
Dim sSQL As String
Combo2.SetFocus
Set rs = New ADODB.Recordset
sSQL = "Select * from user_validate Where user_Name = '" & Combo2.SelText & "'"
rs.Open sSQL, CurrentProject.Connection
' rs.MoveFirst
If rs.EOF Then
MsgBox "User Not Found"
'Prompt again for user name /pwd
Else
'MsgBox "User Found"
'Write Code to Open ur Application
End If
rs.Close
Set rs = Nothing
' commented **** Mithun *****
' Combo2.SetFocus
'sSQL = "SELECT user_validate.user_name FROM user_validate"
'temp = Combo2.SelText
'temp = user_validate.user_name
'If user_validate.user_name = Combo2.SelText And user_validate.password = Text4.Text Then
'sSQL = "Select * From User_validate Where User_Name = '" & Combo2.SelText & "' And Password = '" & Text4.Text & "'"
' stDocName = "dhome"
' DoCmd.OpenForm stDocName, , , stLinkCriteria
' Else
'MsgBox "Invalid user id or password, please try again", vbOKOnly
'End of commented section **** Mithun *****
Exit_Login_Click:
Exit Sub
Err_Login_Click:
MsgBox Err.Description
Resume Exit_Login_Click
' End If
End Sub
Hi Veena,
Thanks a lot for the help and guidance.....
I have a question with regards to setting the focus on an object "
Please could you let me know whether I can explicitly set focus on more than one object at a time. i.e., user name and password fields"
To make set focus
You cannot make set focus for two object at a time
Please could some one provide me the code to validate the user name and password fields using Vb for MS access.
Fields ::
User name :: text box
Password :: text box
Login :: button
The form should accept the user name and password from the text box , validate the same against a table on MS access if successful should allow the user to proceed to next form else display a alert/error message.
Thanks a lot,
Mithun.
Reply from Mr.Jack ( Diploma engineer ) ongoing with AMIE
after dragging controls on active control form
on login button write this following code
a=trim(val(username.text)
b=trim(val(password.text)
while adodc1.recordset.eof<>true
if adodc1.recordset.fields("username")=a then
if adodc1.recordset.fields("password")=b then
login.setfocus
exit sub
else
adodc1.recordset.movenext
end if
else
adodc1.recordset.movenext
end if
wend
msgbox " invalid login",vbinformation
username.text=""
password.text=""
username.setfocus
HI,
Thank you every one for the help and guidance provided. in getting this task completed.
Mentioned below is the final version of the code.
regards,
Mithun
Private Sub Login_Click()
On Error GoTo Err_Login_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim user_name As String
Dim Password As String
Dim temp As String
Dim rs As ADODB.Recordset
Dim rss As ADODB.Recordset
Dim sSQL As String
Dim tSQL As String
Dim x As String
Combo2.SetFocus
Set rs = New ADODB.Recordset
sSQL = "Select password from user_validate Where user_Name = '" & Combo2.SelText & "'"
rs.Open sSQL, CurrentProject.Connection
If rs.EOF Then
MsgBox "Either the user name or password entered are invalid. Please try again. ", vbOKOnly
Else
rs.MoveFirst
While rs.EOF = False
x = rs(0).Value
rs.MoveNext
Wend
Text4.SetFocus
Set rss = New ADODB.Recordset
tSQL = "select * from user_validate where password = ' " & Text4.Text & "'"
rss.Open sSQL, CurrentProject.Connection
If x <> Text4.Text Then
MsgBox "User Not Found"
'Prompt again for user name /pwd
Else
Combo2.SetFocus
MsgBox " " & Combo2.SelText & " Welcome to DESTINATION ONE ", vbOKOnly
DoCmd.Close
stDocName = "dhome"
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Write Code to Open ur Application
End If
End If
rs.Close
Set rs = Nothing
Exit_Login_Click:
Exit Sub
Err_Login_Click:
MsgBox Err.Description
Resume Exit_Login_Click
' End If
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: hkadhim |
last post by:
hi all,
I am trying to validate a user name and password using server 2000 domain
validation. so users would use their normal ID and passwords to login.
does anyone know how to do it or have any...
|
by: mo |
last post by:
The code I've pasted below is taken directly from Microsoft's site at
http://support.microsoft.com/default.aspx?scid=kb;EN-US;308157
As far as I can tell the error is raised on this line:
conn...
|
by: DB2-newbie |
last post by:
As a newbie to DB2 I have a strange problem on a zSeries linux box I
hope someone can answer.
I have created a linux user,
user=mytest
pw=mytest
who is the instance owner and has created a...
|
by: Marc Solé |
last post by:
Hello all,
I have a web application that runs in a server and makes a Windows user
validation to loggin. My question is, how can I get that loggin user,
password and domanin to use it in my...
|
by: joesin |
last post by:
I recently found a vulnerability on my website that allowed sql
injection. I have been trying to write some code that would clean user
data but have been running into problems. The validation still...
|
by: Dmitry |
last post by:
I am trying to figure out how to pass set of credentials to System.IO
Challenge is:
App is running under one set of credentials, but via GUI user have a chance
to enter another set. I would like...
|
by: shapper |
last post by:
Hello,
I am trying to check if a user is valid as follows:
Response.Write(Membership.ValidateUser("usr", "pass").ToString)
It always gives me FALSE.
The username and password are correct....
|
by: ajos |
last post by:
hi frnds,
im trying to convert my servlets database configuration from ms access to mysql database.however im getting some error like no driver found exception.
to verify this error ive...
|
by: AAaron123 |
last post by:
I think I can do this but can't seem to get it to work.
Can I add a few lines to my web.config to allow username ABC to login with
password QWERTYU$$ and role Administrator?
I'm using...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |