Hi Folks, thanks in advance for your time.
I'm pretty new to Access VB so you will have to bear with me.
I have a table tblUser
(userID{PK}, userType, userPassword, userName, Status, numberOfJobs, skillID)
and I have an access form (frmLogin) which contains a Login button
and I am trying to get the form to read in from two text boxes (txtUN, textPW) and search tblUser for the UN (from the textbox), then compare the password to the userPassword, and if they are correct, navigate to one of two other forms depending on the userType.
Now my code theory is fine, but it is just trying to get this to connect to the DB which is never mentioned in these threads... Now I was wondering if one of ou would be kind enough to post some code here to help me, I have tried, unsuccessfully, to populate a recordset with a query (to search) or the =Dlookup() and I can't get wither to work.
Would someone be able to post ALL the code, not just appropriate lines, as I feel I am missing something integeral, yet insanely simple like CurrentDB=DAO.Database or something, so assume I have no globals as yet and am just looking at -
Private Sub btnLogin_Click()
-
-
End Sub
-
Thanks people!
Mark
15 7627
The easy way will be to use the DLOOKUP("fieldname","tablename","where condition") function like:
IF IsNull(DLOOKUP("password","tblMembers","MemberName =" & chr(34) & me.txtMembername " chr(34))) then
' not found
msgbox "Invalid Membername"
end sub
else
if DLOOKUP("password","tblMembers","MemberName=" & chr(34) & me.txtMembername " chr(34)) <> Me.txtPassword then
' wrong password
msgbox "Wrong password"
end sub
else
' OK
endif
endif
The chr(34) is used to neutralize quotes in membernames like O'Neily.
Getting the idea ?
Nic;o)
I keep getting a
"Compile error:
Expected: List separator or )"
Error, something I kept getting myself when I tried.
Any Ideas?
The code has only been changed to suit my tables/values -
Private Sub btnLogin_Click()
-
-
IF IsNull(DLOOKUP("userPassword","tblUser","UserID=" & chr(34) & me.txtMemberName " chr(34))) then
-
-
' not found
-
MsgBox "Invalid Membername"
-
End Sub
-
Else
-
-
if DLOOKUP("userPassword","tblUser","UserID=" & chr(34) & me.txtMemberName " chr(34)) <> Me.txtPassword then
-
-
' wrong password
-
MsgBox "Wrong password"
-
End Sub
-
Else
-
-
' OK
-
End If
-
End If
-
-
End Sub
-
The easy way will be to use the DLOOKUP("fieldname","tablename","where condition") function like:
IF IsNull(DLOOKUP("password","tblMembers","MemberName =" & chr(34) & me.txtMembername " chr(34))) then
' not found
msgbox "Invalid Membername"
end sub
else
if DLOOKUP("password","tblMembers","MemberName=" & chr(34) & me.txtMembername " chr(34)) <> Me.txtPassword then
' wrong password
msgbox "Wrong password"
end sub
else
' OK
endif
endif
The chr(34) is used to neutralize quotes in membernames like O'Neily.
Getting the idea ?
Nic;o)
My code now reads -
Private Sub btnLogin_Click()
-
-
If IsNull(DLookup("userPassword", "tblUser", "UserID=" & Me.txtMembername)) Then
-
-
' not found
-
MsgBox "Invalid Membername"
-
End Sub
-
-
Else
-
If DLookup("userPassword", "tblUser", "UserID=" & Me.txtMembername) <> Me.txtPassword Then
-
-
' wrong password
-
MsgBox "Wrong password"
-
End Sub
-
-
Else
-
' OK
-
-
Text6.Text = "Login ok"
-
-
End If
-
End If
-
End Sub
-
and I am getting no errors when I click the button, but nothing is happening with correct or incorrect data being input, the button just clicks with no actions
Help pls!
OK, try this checked coding: -
Private Sub btnLogin_Click()
-
-
If IsNull(DLOOKUP("userPassword", "tblUser", "UserID=" & chr(34) & Me.txtMembername & chr(34))) Then
-
' not found
-
MsgBox "Invalid Membername"
-
Exit Sub
-
Else
-
If DLOOKUP("userPassword", "tblUser", "UserID=" & chr(34) & Me.txtMembername & chr(34)) <> Me.txtPassword Then
-
' wrong password
-
MsgBox "Wrong password"
-
Exit Sub
-
Else
-
' OK
-
DoCmd.OpenForm "frmForMenu"
-
End If
-
End If
-
-
End Sub
-
Mistake was a " where a & should be used and the END should have been an EXIT.
BTW best to use the password mask on the password field, thus it will show like "*****" when the password is entered, but the value can be used in the code.
Nic;o)
NeoPa 32,511
Expert Mod 16PB
I keep getting a
"Compile error:
Expected: List separator or )"
Error, something I kept getting myself when I tried.
Any Ideas?
The code has only been changed to suit my tables/values
There were a few typo probs with Nico's code.
Here's a modified version : - Private Sub btnLogin_Click()
-
Dim strPW As String
-
-
strPW = Nz(DLookup("userPassword", _
-
"tblUser", _
-
"UserID='" & me.txtUN & "'"), _
-
"EmptyPassword")
-
If strPW = "EmptyPassword" Then
-
'User not found
-
MsgBox "Invalid Username"
-
ElseIf strPW <> txtPassword Then
-
'Invalid Password
-
MsgBox "Wrong password"
-
Else
-
'All OK
-
Call DoCmd.OpenForm("frmForMenu")
-
End If
-
End Sub
PS. Just seen Nico's next version so I nicked his DoCmd in the OK bit and retro-fitted it.
Knowing Nico, his code should work anyway.
HAHA!
Worked perfectly! Thanks very much!
Ur a legend (*HUGS*)
My specialaties are Java, .ASP and MySQL (in Oracle) if you need any help give me a sou anytime!
Mark
OK, try this checked coding: -
Private Sub btnLogin_Click()
-
-
If IsNull(DLOOKUP("userPassword", "tblUser", "UserID=" & chr(34) & Me.txtMembername & chr(34))) Then
-
' not found
-
MsgBox "Invalid Membername"
-
Exit Sub
-
Else
-
If DLOOKUP("userPassword", "tblUser", "UserID=" & chr(34) & Me.txtMembername & chr(34)) <> Me.txtPassword Then
-
' wrong password
-
MsgBox "Wrong password"
-
Exit Sub
-
Else
-
' OK
-
DoCmd.OpenForm "frmForMenu"
-
End If
-
End If
-
-
End Sub
-
Mistake was a " where a & should be used and the END should have been an EXIT.
BTW best to use the password mask on the password field, thus it will show like "*****" when the password is entered, but the value can be used in the code.
Nic;o)
NeoPa 32,511
Expert Mod 16PB
Good for you Mark.
Your question was a pleasure to look at, the question having all the relevant information to hand in the original post :).
There were a few typo probs with Nico's code.
Here's a modified version : - Private Sub btnLogin_Click()
-
Dim strPW As String
-
-
strPW = Nz(DLookup("userPassword", _
-
"tblUser", _
-
"UserID='" & me.txtUN & "'"), _
-
"EmptyPassword")
-
If strPW = "EmptyPassword" Then
-
'User not found
-
MsgBox "Invalid Username"
-
ElseIf strPW <> txtPassword Then
-
'Invalid Password
-
MsgBox "Wrong password"
-
Else
-
'All OK
-
Call DoCmd.OpenForm("frmForMenu")
-
End If
-
End Sub
PS. Just seen Nico's next version so I nicked his DoCmd in the OK bit and retro-fitted it.
Knowing Nico, his code should work anyway.
could you plz explain this code for me?
could you plz explain this code for me?
(Lines with * should be deleted, they are just comments, not even VB comments ( ' ) and they refer to the line of code above)
Private Sub btnLogin_Click()
*The Subroutine to be performed when my button, called btnLogin is clicked*
Dim strPW As String
*Declaring the variable PW of type "String"*
strPW = Nz(DLookup("userPassword", _
"tblUser", _
"UserID='" & me.txtUN & "'"), _
"EmptyPassword")
*I dont know what the "NZ() does here, but the rest of the code uses Dlookup to search the database for a vaule of userPassword, from tblUser table, where the UserID is the same as the value in the text box on the same form (hence me.txtUN) txtUN, and I am assuming that EmptyPassword is the vaule it is forced to return if it is null*
If strPW = "EmptyPassword" Then
'User not found
MsgBox "Invalid Username"
*If the returned value is EmptyPassword then display a msgbox saying Invalid Username*
ElseIf strPW <> txtPassword Then
'Invalid Password
MsgBox "Wrong password"
*If is does not equal the value in the table (<> means not eequal to) then show a message box saying Wrong password*
Else
'All OK
Call DoCmd.OpenForm("frmForMenu")
*Otherwise, if both fields match, open then form called frmForMenu*
End If
End Sub
*End the IF statement, and end the Sub routine*
Hope I got it right, and hope it helps!
Looks OK to me, the NZ(<string>,<value used when string is Null>) does indeed work as assumed.
Nic;o)
Hello,
I have used this code for implementing password on the access database I am building and it works well except for one situation:
If I input a correct username, but I leave the password Textbox empty, it still performs the programmed action as if the username/password were correct and matching.
How come ? Any Idea ?
Thank you for your answer and best regards,
G.
Re,
I have resolved my issue by inserting those lines (bold): - Private Sub Login_Password_Click()
-
- If IsNull(txtPassword) Then
-
txtPassword = "*"
-
End If
-
-
Dim strPW As String
-
-
strPW = Nz(DLookup("Password", _
-
"tblUsername", _
-
"Username='" & Me.txtUsername & "'"), _
-
"EmptyPassword")
-
If strPW = "EmptyPassword" Then
-
-
MsgBox "Invalid Username"
-
-
ElseIf strPW <> txtPassword Then
-
-
MsgBox "Wrong Password"
-
Else
-
-
Call DoCmd.RunMacro("DELETE_OK")
-
End If
-
-
End Sub
But is there any other better way to do it ?
And btw, is the password case-sensitive here?
Thank you for your replies.
Best regards,
G.
Re,
I have resolved my issue by inserting those lines (bold): - Private Sub Login_Password_Click()
-
- If IsNull(txtPassword) Then
-
txtPassword = "*"
-
End If
-
-
Dim strPW As String
-
-
strPW = Nz(DLookup("Password", _
-
"tblUsername", _
-
"Username='" & Me.txtUsername & "'"), _
-
"EmptyPassword")
-
If strPW = "EmptyPassword" Then
-
-
MsgBox "Invalid Username"
-
-
ElseIf strPW <> txtPassword Then
-
-
MsgBox "Wrong Password"
-
Else
-
-
Call DoCmd.RunMacro("DELETE_OK")
-
End If
-
-
End Sub
But is there any other better way to do it ?
And btw, is the password case-sensitive here?
Thank you for your replies.
Best regards,
G.
Hey thanks very much for that, I actually had never tested that with a null value, and had never noticed the error!
And no, I dont think access is case sensitive
Most welcome and thank you for the answer about case sensitiveness.
I have inserted those lines, being the best way I found to get rid of the problem. But I guess this is just a "trick". So, if someone knows a better way of coding that...
Best regards,
G.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: arktikturtle |
last post by:
Hi! I'm looking for a way to validate a password within PL/SQL. I want to
write
CREATE PROCEDURE change_password(old_password IN VARCHAR2)
IS
BEGIN
-- check if old_password is correct... but...
|
by: Steffen Balslev |
last post by:
I tried to find a way to validate user credentials using C#, searching google and lots of other news and kb sites left me without a solution.
You can use a SSPI but it's that easy to implement so...
|
by: Wysiwyg |
last post by:
I need to validate a form to ensure that all of the fields add up correctly.
I can't do this while the user is entering data since validation needs to be
done after the entry is completed. What's...
|
by: hary08 |
last post by:
im doing a database for Hospital Admission, I have a log in form which prompt user for a password. The source of log in is to look for the values in my Table tblEmployees and match user name and...
|
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: Kodiak |
last post by:
I create a DirectoryEntry object called userEntry and I am calling the
Invoke method. I am calling the SetPassword method and passing the
new password and I am using the DirectoryServices...
|
by: JodiPhillips |
last post by:
G'day,
I have a silly and simple problem that I need some guidance with.
Due to the way our network is set up, I am unable to use the group permissions for Access and have had to implement log...
|
by: vikas251074 |
last post by:
I am using ASP
In my company, all employees have to sent materials out of premises. Any employee who need to sent material out will use this web application. In the first page, an employee enters...
|
by: jmurphy |
last post by:
What do i add to this script to validate the entry?
Thanks in advance for the help.
<form name="continue" method="POST" action="shipping1.asp" onsubmit="return validate_form ();">
<input...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
| |