Link to home
Start Free TrialLog in
Avatar of military donut
military donutFlag for United States of America

asked on

Db startup dlookup not working

Hello I have the below code and on the part

Check=
I get an error
The expression you entered as a query parameter produced this error 'username' (this shows the username if the person on the computer)

Again I have this running on startup as an autoexec
I have the function : CheckName running first thing

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function


Public Function CheckName()
Call fOSUserName
Dim Check As String
Dim User As String
User = fOSUserName

Check = DLookup("UserName", "tblUser", User)
Debug.Print Check

If fOSUserName = Check Then
    Call DisClaimStartup
    

Else
    MsgBox "You must be a valid User to use SLED"
    DoCmd.Quit
    Cancel = True
    Exit Function
End If
End Function

Open in new window

SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of military donut

ASKER

Invalid use of null..

Edited this response

?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Both of you are absolutely right.  I wasn't thinking clearly on the null .

Thanks to both of you. Great help!
oops

Check = DLookup("UserName", "tblUser", "[UserName] = " & Chr(34)  & User & Chr(34) )