I have a problem; i know its a simple code but find it difficult to contruct the code.
I have two fields username and password. I need some code, when a user clicks the button event in the form it checks against the username and password in the table to see if its correct; if correct it let you login else a message box should show either the username or password is wrong.
Can someone give me a sniplet of the code that i could use.
Thanks
9 8169
I have a problem; i know its a simple code but find it difficult to contruct the code.
I have two fields username and password. I need some code, when a user clicks the button event in the form it checks against the username and password in the table to see if its correct; if correct it let you login else a message box should show either the username or password is wrong.
Can someone give me a sniplet of the code that i could use.
Thanks
Put the following in the button click event. Assuming textbox on form for username is txtUser and for password is txtPass. - Dim password As String
-
-
If Not IsNull(Me.txtUser) Then
-
password = DLookup("Password","tblUsers","[UserName]=" & Me.txtUser)
-
If Not IsNull(password) Then
-
If Not IsNull(Me.txtPass) Then
-
If password = Me.txtPass
-
'Code to Proceed goes here
-
Else
-
Msgbox "You have entered an incorrect password, please re-enter", vbOkOnly
-
Exit Sub
-
End If
-
Else
-
Msgbox "You must enter a password", vbOkOnly
-
Exit Sub
-
End If
-
Else
-
Msgbox "You have entered an incorrect username, please re-enter", vbOkOnly
-
End if
-
Else
-
Msgbox "You must enter a user name.", vbOKOnly
-
Exit Sub
-
End If
Mary
I inserted this code in the button click event handler but keep on getting a command syntax error on If password = Me.txtPass.
at present my table has three field loginid, username and password. Do i have to specify the table through a select statement.
Private Sub go_Click()
On Error GoTo Err_go_Click
Screen.PreviousControl.SetFocus
Dim password As String
If Not IsNull(Me.txtUser) Then
password = DLookup("Password", "tblUsers", "[UserName]=" & Me.txtUser)
If Not IsNull(password) Then
If Not IsNull(Me.txtPass) Then
If password = Me.txtPass
Else
MsgBox "You have entered an incorrect password, please re-enter", vbOKOnly
Exit Sub
End If
Else
MsgBox "You must enter a password", vbOKOnly
Exit Sub
End If
Else
MsgBox "You have entered an incorrect username, please re-enter", vbOKOnly
End If
Else
MsgBox "You must enter a user name.", vbOKOnly
Exit Sub
End If
End Sub
Put the following in the button click event. Assuming textbox on form for username is txtUser and for password is txtPass. -
Dim password As String
-
-
If Not IsNull(Me.txtUser) Then
-
password = DLookup("Password","tblUsers","[UserName]=" & Me.txtUser)
-
If Not IsNull(password) Then
-
If Not IsNull(Me.txtPass) Then
-
If password = Me.txtPass
-
'Code to Proceed goes here
-
Else
-
Msgbox "You have entered an incorrect password, please re-enter", vbOkOnly
-
Exit Sub
-
End If
-
Else
-
Msgbox "You must enter a password", vbOkOnly
-
Exit Sub
-
End If
-
Else
-
Msgbox "You have entered an incorrect username, please re-enter", vbOkOnly
-
End if
-
Else
-
Msgbox "You must enter a user name.", vbOKOnly
-
Exit Sub
-
End If
-
Mary
I was only using these as an example as I didn't know what the textboxes on the form were called. Replace txtUser and txtPass with the name of the textboxes on the login form. -
Private Sub go_Click()
-
On Error GoTo Err_go_Click
-
Screen.PreviousControl.SetFocus
-
Dim password As String
-
-
If Not IsNull(Me.txtUser) Then
-
password = DLookup("Password", "tblUsers", "[UserName]=" & Me.txtUser)
-
If Not IsNull(password) Then
-
If Not IsNull(Me.txtPass) Then
-
If password = Me.txtPass
-
-
-
Else
-
MsgBox "You have entered an incorrect password, please re-enter", vbOKOnly
-
Exit Sub
-
End If
-
Else
-
MsgBox "You must enter a password", vbOKOnly
-
Exit Sub
-
End If
-
Else
-
MsgBox "You have entered an incorrect username, please re-enter", vbOKOnly
-
End If
-
Else
-
MsgBox "You must enter a user name.", vbOKOnly
-
Exit Sub
-
End If
-
End Sub
I tried what you showed me, i still get the same error;
"compile error: Syntax Error" on If password = Me.txtPass
Not sure whats the problem. I've named my textboxes as txtUser & txtPass - but still get the error. Try on your one - i'm giving up on this now.
Thanks for your help
Add 'Then' to the end of the line - If password = Me.txtPass Then
now i get
run time error '94'
invalid use of null
-
Private Sub go_Click()
-
On Error GoTo Err_go_Click
-
Screen.PreviousControl.SetFocus
-
Dim password As String
-
-
If Not IsNull(Me.txtUser) Then
-
password = DLookup("Password", "tblUsers", "[UserName]=" & Me.txtUser)
-
If Not IsNull(password) Then
-
If Not IsNull(Me.txtPass) Then
-
If password = Me.txtPass Then
-
'**************** Your code here***********
-
Else
-
MsgBox "You have entered an incorrect password, please re-enter", vbOKOnly
-
Exit Sub
-
End If
-
Else
-
MsgBox "You must enter a password", vbOKOnly
-
Exit Sub
-
End If
-
Else
-
MsgBox "You have entered an incorrect username, please re-enter", vbOKOnly
-
End If
-
Else
-
MsgBox "You must enter a user name.", vbOKOnly
-
Exit Sub
-
End If
-
End Sub
All possible nulls should be accounted for in the above code. What line exactly is your code stopping at.
Mary
The Null is stopping at:
password = DLookup("Password", "tblUsers", "[UserName]=" & Me.txtUser).
Also if i keep the:
On Error GoTo Err_go_Click
then i get this error: Label not defined.
If i delete that line then the null error comes in.
Thanks for all your help
Try changing password variable to a variant as follows: -
Private Sub go_Click()
-
On Error GoTo Err_go_Click
-
Screen.PreviousControl.SetFocus
-
Dim password As Variant
-
-
If Not IsNull(Me.txtUser) Then
-
password = DLookup("Password", "tblUsers", "[UserName]=" & Me.txtUser)
-
If Not IsNull(password) Then
-
If Not IsNull(Me.txtPass) Then
-
If password = Me.txtPass Then
-
'**************** Your code here***********
-
Else
-
MsgBox "You have entered an incorrect password, please re-enter", vbOKOnly
-
Exit Sub
-
End If
-
Else
-
MsgBox "You must enter a password", vbOKOnly
-
Exit Sub
-
End If
-
Else
-
MsgBox "You have entered an incorrect username, please re-enter", vbOKOnly
-
End If
-
Else
-
MsgBox "You must enter a user name.", vbOKOnly
-
Exit Sub
-
End If
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: pv |
last post by:
Hi everyone,
I need help with following scenario, please:
Users are accessing same web server from intranet (users previously
authenticated in Active Dir) and from extranet (common public...
|
by: AppleBag |
last post by:
I'm having the worst time trying to login to myspace through code. Can
someone tell me how to do this? Please try it yourself before replying,
only because I have asked this a couple of times in...
|
by: tolkienarda |
last post by:
Hi all
I work for a small webdesign company and we have remote hosting. i built a mysql database with phpmyadmin on the server. i then downloaded and modified a php login page. i am continuing to...
|
by: xcelmind |
last post by:
Hello Dev. Guru,
I want to at this time introduce myself. I am Stanley Ojadovwa by name.
I’m a freelance and a newbie in web application development. I’m
currently using ASP as my application...
|
by: Freedolen |
last post by:
Hi All,
I had a perl script which is used to login in a web page, but it gives the error as
"301 Moved Permanently". What does this means and how can it be rectified?
Can anyone help on this?
...
|
by: satishknight |
last post by:
Hi,
Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
|
by: DavidPr |
last post by:
When I logout as one user and log in under a different user, it opens with the last user's information.
User 1 - Unsername: Davey Jones
User 2 - Unsername: David Smith
I log out from Davey...
|
by: adweaver |
last post by:
Hello All,
I'm new to the world of php. I've just had a site designed for me by a company, and I'm now trying to manage and grow it, so it will suit my needs.
The site was built in a folder...
|
by: Apostle |
last post by:
Hi all, after thinking for sometimes, I thought it will be great opportunity to learn if I will start from scratch and build my own register/login system. Here is the thread that I will be posting...
|
by: punk86 |
last post by:
Hi,
i can register and login without fail.
However i notice that my inputs are not record into the database.
I do not know the reason.
Can someone guide me into login and register.
Actually im...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: 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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |