By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,728 Members | 1,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,728 IT Pros & Developers. It's quick & easy.

Login Form with Multi user login

P: 13
Hi I have this project currently on going and I'm stack in the login form, I've done most of the part but still i cant seem to find a solution to this part.

the login form has 2 Textbox and 1 Combobox (usernameTB, passwordTB, userTypeCB) im finish with the part of comparing the username and the password whether the two match in my table, but what i cant seem to do is compare whether the user type(Administrator, Standard User) match the datas in the table.

HERE is my code so far and whenever I try to login using this codes it keeps on telling me "Run-time error '2471': The expression you entered as a query parameter produced this error: 'Administrator' (TAKE NOTE that the value's in the userTypeCB are "Administrator" and "Standard User"

one last thing, this isnt the complete code because this is a copy my project that im working on, i made a diff. copy so that i could do whatever i want without the harm of totally ruining the whole project. Any help would be appreciated. Thanks!

Expand|Select|Wrap|Line Numbers
  1. Private Sub signinBTN_Click()
  2.  
  3. Dim adminType As String
  4. Dim userType As String
  5.  
  6. If IsNull(Me.usernameTB) Then
  7.     MsgBox "Please enter a username", vbInformation, "Need Username!"
  8.         Me.usernameTB.SetFocus
  9.     Exit Sub
  10. End If
  11.  
  12. If IsNull(Me.passwordTB) Then
  13.     MsgBox "Please enter a password!", vbInformation, "Need Password!"
  14.         Me.passwordTB.SetFocus
  15.     Exit Sub
  16. End If
  17.  
  18.  
  19. If Nz(DLookup("Password", "UserINFO", "Username = '" & Me.usernameTB & "'"), "GarbageEntry") = Me.passwordTB Then
  20.  
  21.     MsgBox "User Found!", vbOKOnly
  22.  
  23.     If Me.passwordTB.Value = DLookup("Password", "userINFO", "ID =" & Me.userTypeCB.Value) Then
  24.  
  25.     ID = Me.userTypeCB.Value
  26.  
  27.     MsgBox "password and user type match!"
  28.  
  29.     Else
  30.  
  31.     MsgBox "they dont match!"
  32.  
  33.     End If
  34.  
  35. Else
  36.     MsgBox "Incorrect Username or Password"
  37.  
  38.         Me.usernameTB = ""
  39.         Me.passwordTB = ""
  40.         Me.usernameTB.SetFocus
  41.  
  42. End If
  43. End Sub
Jun 24 '15 #1
Share this Question
Share on Google+
5 Replies


P: 13
No need to answer my question, I've already solved it, the problem is with my data field "User Type" it seems Access VBA wont allow any space in the Dlookup method. Tried to remove the "space" in the data field and it worked. :)
Jun 24 '15 #2

zmbd
Expert Mod 5K+
P: 5,397
Certainly Dlookup will allow this, you have to properly format the string.

It also appears that you also did not include the section of the code that has that Dlookup...
Jun 24 '15 #3

NeoPa
Expert Mod 15k+
P: 31,769
If you have a reference that includes a space in it, which is never a good idea, then you can put square brackets ([]) around the string value to get it to be recognised almost anywhere in Access, and most other databases too.
Jun 25 '15 #4

P: 13
Expand|Select|Wrap|Line Numbers
  1. If Nz(DLookup("UserType", "userINFO", "Username = '" & Me.usernameTB & "'"), "GarbageEntry") = Me.userTypeCB Then
this is the line that has space on it, it should be in line 24, forgot to add it. The one that has the space is the data field "UserType" it used to be "User Type", dunno why it worked when i removed the space in between, but im happy now that it did.
Jun 25 '15 #5

P: 13
Thank you for that tip NeoPa, ill always remember it.
Jun 25 '15 #6

Post your reply

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