473,395 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Login Code

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
Feb 27 '07 #1
9 8169
MMcCarthy
14,534 Expert Mod 8TB
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.

Expand|Select|Wrap|Line Numbers
  1. Dim password As String
  2.  
  3. If Not IsNull(Me.txtUser) Then
  4.   password = DLookup("Password","tblUsers","[UserName]=" & Me.txtUser)
  5.   If Not IsNull(password) Then
  6.     If Not IsNull(Me.txtPass) Then
  7.       If password = Me.txtPass
  8.         'Code to Proceed goes here
  9.       Else
  10.         Msgbox "You have entered an incorrect password, please re-enter", vbOkOnly
  11.         Exit Sub
  12.       End If
  13.     Else
  14.       Msgbox "You must enter a password", vbOkOnly
  15.       Exit Sub
  16.     End If
  17.   Else
  18.     Msgbox "You have entered an incorrect username, please re-enter", vbOkOnly
  19.   End if
  20. Else
  21.   Msgbox "You must enter a user name.", vbOKOnly
  22.   Exit Sub
  23. End If
Mary
Feb 27 '07 #2
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.

Expand|Select|Wrap|Line Numbers
  1. Dim password As String
  2.  
  3. If Not IsNull(Me.txtUser) Then
  4.    password = DLookup("Password","tblUsers","[UserName]=" & Me.txtUser)
  5.    If Not IsNull(password) Then
  6.       If Not IsNull(Me.txtPass) Then
  7.          If password = Me.txtPass
  8.             'Code to Proceed goes here
  9.          Else
  10.             Msgbox "You have entered an incorrect password, please re-enter", vbOkOnly
  11.             Exit Sub
  12.          End If
  13.       Else
  14.          Msgbox "You must enter a password", vbOkOnly
  15.          Exit Sub
  16.       End If
  17.    Else
  18.       Msgbox "You have entered an incorrect username, please re-enter", vbOkOnly
  19.    End if
  20. Else
  21.    Msgbox "You must enter a user name.", vbOKOnly
  22.    Exit Sub
  23. End If
  24.  
Mary
Feb 27 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub go_Click()
  2. On Error GoTo Err_go_Click
  3.   Screen.PreviousControl.SetFocus
  4. Dim password As String
  5.  
  6. If Not IsNull(Me.txtUser) Then
  7.    password = DLookup("Password", "tblUsers", "[UserName]=" & Me.txtUser)
  8.    If Not IsNull(password) Then
  9.       If Not IsNull(Me.txtPass) Then
  10.          If password = Me.txtPass
  11.  
  12.  
  13.              Else
  14.             MsgBox "You have entered an incorrect password, please re-enter", vbOKOnly
  15.             Exit Sub
  16.          End If
  17.       Else
  18.          MsgBox "You must enter a password", vbOKOnly
  19.          Exit Sub
  20.       End If
  21.    Else
  22.       MsgBox "You have entered an incorrect username, please re-enter", vbOKOnly
  23.    End If
  24. Else
  25.    MsgBox "You must enter a user name.", vbOKOnly
  26.    Exit Sub
  27. End If
  28. End Sub
Feb 27 '07 #4
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
Feb 28 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Add 'Then' to the end of the line

Expand|Select|Wrap|Line Numbers
  1. If password = Me.txtPass Then
Feb 28 '07 #6
now i get
run time error '94'
invalid use of null
Feb 28 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. Private Sub go_Click()
  2. On Error GoTo Err_go_Click
  3.   Screen.PreviousControl.SetFocus
  4. Dim password As String
  5.  
  6. If Not IsNull(Me.txtUser) Then
  7.    password = DLookup("Password", "tblUsers", "[UserName]=" & Me.txtUser)
  8.    If Not IsNull(password) Then
  9.       If Not IsNull(Me.txtPass) Then
  10.          If password = Me.txtPass Then
  11.            '**************** Your code here***********
  12.          Else
  13.             MsgBox "You have entered an incorrect password, please re-enter", vbOKOnly
  14.             Exit Sub
  15.          End If
  16.       Else
  17.          MsgBox "You must enter a password", vbOKOnly
  18.          Exit Sub
  19.       End If
  20.    Else
  21.       MsgBox "You have entered an incorrect username, please re-enter", vbOKOnly
  22.    End If
  23. Else
  24.    MsgBox "You must enter a user name.", vbOKOnly
  25.    Exit Sub
  26. End If
  27. End Sub
All possible nulls should be accounted for in the above code. What line exactly is your code stopping at.

Mary
Feb 28 '07 #8
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
Feb 28 '07 #9
MMcCarthy
14,534 Expert Mod 8TB
Try changing password variable to a variant as follows:

Expand|Select|Wrap|Line Numbers
  1. Private Sub go_Click()
  2. On Error GoTo Err_go_Click
  3.   Screen.PreviousControl.SetFocus
  4. Dim password As Variant
  5.  
  6. If Not IsNull(Me.txtUser) Then
  7.    password = DLookup("Password", "tblUsers", "[UserName]=" & Me.txtUser)
  8.    If Not IsNull(password) Then
  9.       If Not IsNull(Me.txtPass) Then
  10.          If password = Me.txtPass Then
  11.            '**************** Your code here***********
  12.          Else
  13.             MsgBox "You have entered an incorrect password, please re-enter", vbOKOnly
  14.             Exit Sub
  15.          End If
  16.       Else
  17.          MsgBox "You must enter a password", vbOKOnly
  18.          Exit Sub
  19.       End If
  20.    Else
  21.       MsgBox "You have entered an incorrect username, please re-enter", vbOKOnly
  22.    End If
  23. Else
  24.    MsgBox "You must enter a user name.", vbOKOnly
  25.    Exit Sub
  26. End If
  27. End Sub
Mar 1 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
6
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...
4
tolkienarda
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...
1
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...
4
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? ...
3
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...
10
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...
9
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...
13
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...
1
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...
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.