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

dlookup string syntax - need help

P: n/a
I thought I had this process pretty well down pat, but I'm getting a
syntax error on the following code:

*****Code*****
'Check for users - can't get this to work...
Dim strUser As String

strUser = WUserName()

If IsNull(DLookup("Permitted", "tblUsers", "Permitted = '" &
strUser & "'")) Then

MsgBox ("Sorry, " & strUser & " you do not have permission to
use this database")
DoCmd.Quit
End If
******************

Here is what the error message looks like when it looks me up (dgard):

syntax error in string query expression 'Permitted = 'dgard'.

If I change strUser to "dgard", the query works properly, so I'm
guessing it has something to do with the user lookup process.

Here is the code for the WUserName() function:

******Code*********
Public Function WUserName() As String
On Error Resume Next
WUserName = " "
Dim strName As String
strName = Space(8)
Call GetUserName(strName, 8)

WUserName = strName
End Function

Declare Function GetUserName _
Lib "advapi32.dll" _
Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long
********************

Any ideas would be of great help to me, thanks!

Diana

Mar 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Diana" <di*******@yahoo.com> wrote in
news:11**********************@j52g2000cwj.googlegr oups.com:

Here is the code for the WUserName() function:

******Code*********
Public Function WUserName() As String
On Error Resume Next
WUserName = " "
Dim strName As String
strName = Space(8)
Call GetUserName(strName, 8)

The problem is in the line below: WUserName = strName it's returning a string with the user name, a null and the rest
of the string.

this is the fix.
WUserName = Left(Trim((strName)), Len(Trim(strName)) - 1) Any ideas would be of great help to me, thanks!

Diana


--
Bob Quintal

PA is y I've altered my email address.
Mar 15 '06 #2

P: n/a
Thanks, so much, Bob! That solved it.

Diana

Bob Quintal wrote:
"Diana" <di*******@yahoo.com> wrote in
news:11**********************@j52g2000cwj.googlegr oups.com:

Here is the code for the WUserName() function:

******Code*********
Public Function WUserName() As String
On Error Resume Next
WUserName = " "
Dim strName As String
strName = Space(8)
Call GetUserName(strName, 8)


The problem is in the line below:
WUserName = strName

it's returning a string with the user name, a null and the rest
of the string.

this is the fix.
WUserName = Left(Trim((strName)), Len(Trim(strName)) - 1)
Any ideas would be of great help to me, thanks!

Diana


--
Bob Quintal

PA is y I've altered my email address.


Mar 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.