473,385 Members | 1,752 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,385 software developers and data experts.

vba login code wont work

ive been trying to get this code to work for a few days now, but i dont know what im doing wrong :S
im basicaly trying to create a login that will allow members to login to their details.
the code i have will only run the look up, and give a msgbox if there is no username or password inputed.
i have an invisble textbox that sends the password to that when the username is inputed in th txtbox for the username (txtUser)
the lookup works, however, when i type in the correct password into the txtbox for the password (txtPass) and click the button, it comes up with the error msg saying "Invalid Username/Password. Please try again."
ive been changing things around and adding different code but nothing has worked so far :/

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEnter_Click()
  2.  
  3.     If IsNull(Me.txtUser) Or Me.txtUser = "" Then
  4.         MsgBox "You must enter a username.", vbOKOnly, "Required Data"
  5.             Me.txtUser.SetFocus
  6.         Exit Sub
  7.     End If
  8.  
  9.  
  10.     If IsNull(Me.txtPass) Or Me.txtPass = "" Then
  11.         MsgBox "You must provide a password.", vbOKOnly, "Required Data"
  12.             Me.txtPass.SetFocus
  13.         Exit Sub
  14.     End If
  15.  
  16.  
  17.     Me.txtlookup.Value = DLookup("[Password]", "qryCustomerAccess", "[FirstName] ='" & Me.txtUser & "'")
  18.  
  19.  
  20. 'Compare value of Password to PassLookup and
  21.  
  22.     If Me.txtPass.Value = Me.txtlookup.Value Then
  23.  
  24.  
  25.              DoCmd.OpenForm "frmRes"
  26.  
  27.     Else
  28.             MsgBox "Invalid Username/Password. Please try again.", vbOKOnly, "Invalid Entry!"
  29.  
  30.         Exit Sub
  31.     End If
  32.  
  33.     End Sub
  34.  
Feb 23 '11 #1

✓ answered by beacon

Looking back on your code, it looks like the Me.txtPass holds a string instead of a number...at least that's how you're handling the null or blank values.

Have you tried assigning the value that you're putting in the Me.txtlookup to a variable and converting the value to a string before comparing it to Me.txtPass?

Or, vice versa, you could assign the value in Me.txtPass to a variable and convert the value to a number.

5 3136
beacon
579 512MB
Hi Die,

Have you added breakpoints to your code to confirm that the values of the txtPass and txtlookup fields are equal when you run the code?

I'm not sure if this will work, but you could combine part of your code together so that you are comparing the value in Me.txtPass directly to the corresponding field in the query instead of assigning the value to a textbox and then comparing.

Here's the modified code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEnter_Click() 
  2.  
  3.     If IsNull(Me.txtUser) Or Me.txtUser = "" Then 
  4.         MsgBox "You must enter a username.", vbOKOnly, "Required Data" 
  5.             Me.txtUser.SetFocus 
  6.         Exit Sub 
  7.     End If 
  8.  
  9.  
  10.     If IsNull(Me.txtPass) Or Me.txtPass = "" Then 
  11.         MsgBox "You must provide a password.", vbOKOnly, "Required Data" 
  12.             Me.txtPass.SetFocus 
  13.         Exit Sub 
  14.     End If 
  15.  
  16.  
  17.     Me.txtlookup.Value = DLookup("[Password]", "qryCustomerAccess", "[FirstName] ='" & Me.txtUser & "'") 
  18.  
  19.  
  20. 'Compare value of Password to PassLookup and 
  21.  
  22.     If Me.txtPass.Value = DLookup("[Password]", "qryCustomerAccess", "[FirstName] ='" & Me.txtUser & "'") Then 
  23.  
  24.  
  25.              DoCmd.OpenForm "frmRes" 
  26.  
  27.     Else 
  28.             MsgBox "Invalid Username/Password. Please try again.", vbOKOnly, "Invalid Entry!" 
  29.  
  30.         Exit Sub 
  31.     End If 
  32.  
  33. End Sub 
  34.  
I would also check that the underlying field for your [Password] field is a string, or that it at least matches the format of the textbox control on your form.
Feb 23 '11 #2
hey beacon,

unfortunatly, the modified code didnt work :\
it still comes up with the same invalid entry message box
even though the passwords match

my format in the field for the Password is Number
how would i make the txtbox the same??
Feb 24 '11 #3
beacon
579 512MB
Looking back on your code, it looks like the Me.txtPass holds a string instead of a number...at least that's how you're handling the null or blank values.

Have you tried assigning the value that you're putting in the Me.txtlookup to a variable and converting the value to a string before comparing it to Me.txtPass?

Or, vice versa, you could assign the value in Me.txtPass to a variable and convert the value to a number.
Feb 24 '11 #4
you were right!!
it had to do with the format of the password!
it finally works after almost a week of trying to figure it out :)
funny how something so small and simple can have a big impact on something :P lol
Feb 25 '11 #5
beacon
579 512MB
I'm glad it worked for you.

I should also point out that if the password is a string and you want the password to be case sensitive you can use the StrComp function with the VBBinaryComplete comparison (third argument in the function) to make the determination. If the function returns 0, then the two strings are equal and the case is identical.
Feb 26 '11 #6

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

Similar topics

3
by: Oliver Spiesshofer | last post by:
Hi, I have a script that calls an fopen() on an external URL. I can run the script from the server as an url fine. When however the script should be run from crontab, it does not work. I get ...
5
by: Catherine | last post by:
I am having a problem viewing asp pages on iis version 5.1 xp pro. HTML pages are viewable on http://localhost but .asp pages are not. I have created a test program called timetest.asp with the...
19
by: Allen Thompson | last post by:
sorry for the simple question, haven't done this in a while. when I use the following script it keeps displaying the value of "x" like a string. for example, if I type the number 7 in the prompt,...
2
by: Tony Williams | last post by:
I have this code behind a command button but it doesn't delete the record. If vbNo = MsgBox("Are you sure you want to save this new record?", 4) Then DoCmd.DoMenuItem acFormBar, acEditMenu, 8, ,...
0
by: Sebastian Sosna | last post by:
Hi there! iam trying a code snippet from MSDN heres the link : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/netds/creating_groups.asp ive tried the code but it...
7
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns...
14
by: squash | last post by:
The following code works fine in Firefox/Netscape but wont work in IE. I suspect the problem is with one of these two simple functions. If there is no obvious error Ill paste the entire code. ...
2
by: NDayave | last post by:
How do, A while ago i had the problem of backing up a Access 2002 table with unique data that changed in some tables but not others, resulting in restore failure. This was sorted by NeoPa with the...
2
by: jcollins1991 | last post by:
im trying to make a program thats supposed to check whether 2 strings are anagrams of each other (anagram = same letters in both strings, but in different orders... "cool as wet art" , and "cs at...
3
by: ukfusion | last post by:
I have a php page with a form....the form has a hidden variable called subjoin. with a value of 1 in the page the data is posted to i have the following code <?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
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
Oralloy
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,...
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...

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.