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

dlookup again

P: 64
Hi...can anyone solve this code for me...I don't know why when I log as Admin that I set as Integer which 1 = Admin and 2 = User

Below is the coding of retrieve the data by using dlookup

Expand|Select|Wrap|Line Numbers
  1. Dim security As Integer
  2. Dim user As String
  3.  
  4. user = Environ("USERNAME")
  5. Me.txtUser = user
  6. Me.txtUsername = DLookup("UserName", "User", "[UserName]='" & user & "'")
  7.  
  8. If IsNull(DLookup("UserSecurity", "User", "[UserLogin]='" & Me.txtUser & "'")) Then
  9.     MsgBox "No User Security set up for this user. Please contact the Admin", vbOKOnly, "Login Info"
  10.     Me.Command175.Visible = False
  11. Else
  12.     security = DLookup("UserSecurity", "User", "[UserLogin]='" & Me.txtUser.Value & "'")
  13.     If security = 1 Then
  14.         Me.Command175.Visible = True
  15.     Else
  16.         Me.Command175.Visible = False
  17.     End If
  18. End If

The problem when I access as admin it will go on the line 8 until 10

Can anyone help me?
Apr 30 '15 #1
Share this Question
Share on Google+
2 Replies


jforbes
Expert 100+
P: 1,107
I don't really understand what problem you are encountering. If you would like to clarify what your error is, that might be helpful.

Looking at your code, there are a few things that I would do differently:
Expand|Select|Wrap|Line Numbers
  1. Dim security As Integer
  2. Dim user As String
  3.  
  4. user = Environ("USERNAME")
  5. Me.txtUser = user
  6. Me.txtUsername = Nz(DLookup("UserName", "User", "[UserName]='" & user & "'"), "")
  7. security = Nz(DLookup("UserSecurity", "User", "[UserLogin]='" & user & "'"), 0)
  8.  
  9. Dim security As Integer
  10. Dim user As String
  11.  
  12. user = Environ("USERNAME")
  13. Me.txtUser = user
  14. Me.txtUsername = Nz(DLookup("UserName", "User", "[UserName]='" & user & "'"), "")
  15. security = Nz(DLookup("UserSecurity", "User", "[UserLogin]='" & user & "'"), 0)
  16.  
  17. ' Hide Everything First
  18. Me.Command175.Visible = False
  19.  
  20. Select Case security
  21.     Case 1
  22.         Me.Command175.Visible = True
  23.     Case Else
  24.         MsgBox "No User Security set up for this user. Please contact the Admin.", vbOKOnly, "Login Info"
  25. End Select
Apr 30 '15 #2

P: 64
Thanks for replying..@jforbes

The problem that happen to me was...as you know..my table field for user has been set which Admin as 1 and User as 2....The problem in my coding...it cannot lookup the Admin as 1...they insist to as User = 2...eventhough I put it as Admin, it still go to User which is no = 2....
May 2 '15 #3

Post your reply

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