Lookup does not want to work

User avatar
sistemaPR
2StarLounger
Posts: 119
Joined: 01 Jul 2013, 14:08

Lookup does not want to work

Post by sistemaPR »

Sub Showmethename()
Dim loguser As String
Dim uname As String

loguser = Environ("UserName")

MsgBox " This is the name " & (loguser)

uname = DLookup("Fullname", "tbl-Permissions", "LoginName= 'loguser'")

MsgBox (uname)

End Sub

why this does not work ?

the problen seen to be with the variable loguser ??? I dont know why

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Lookup does not want to work

Post by HansV »

"LoginName= 'loguser'" is a literal, fixed string. It makes the code look for a user named literally loguser. You must place loguser outside the quotes:

Code: Select all

uname = DLookup("Fullname", "tbl-Permissions", "LoginName= '" & loguser & "'")
Best wishes,
Hans