AutoExec calling Function Error 2425

cstickman

Registered User.
Local time
Today, 17:11
Joined
Nov 10, 2014
Messages
109
I am starting a new project and I would like to use the AutoExec Macro for this one. I have the following function and when calling the function I keep getting the error "The expression you entered has a function name that Microsoft access can't find". Here is the function code

Code:
 Option Compare Database
Option Explicit
 Public Function OpenCHeck()
     Dim varUser
    Dim varOK
    
    varUser = Environ("username")
    
    varOK = DLookup("[racfid]", "tbluser", "[racfid] = '" & varUser & "'")
    
    If IsNull(varOK) Then
        MsgBox "Get outa here loser", vbExclamation
        DoCmd.Quit
    End If
 End Function

Do I need to reference something? I cannot figure it out.

The Macro is setup as RunCode - Function Name OpenCHeck()
 
IDs are usually numeric, here you are looking up [racfID] as string
"[racfid] = '" & varUser & "'")
is this correct?

Is Environ("username") returning anything?
try it in debug window.
 
Also make sure the function is in a standard module, not in a form/report module.
 
racfid is actually a username field and is set as text. As an example it would be jdoe

I added the module by going to the visual basic editor and clicked on insert and then module. Do I do it a different way? I believe that was the first thing I did when I started the new database.
 
You didn't name the module the same as the function did you? Can't do that if so.
 
PBaldy - I actually did for some reason. Thanks for catching that. Now I have this runtime error 94 invalid use of DLookup and it highlights this row

varOK = DLookup("racfid", "tbluser", "racfid = """ & varUser & """")

Any Ideas?
 
Nevermind, I got it. So here is the actual working code for other users if they come across the same problem or want to do what I am doing.

Code:
 Public Function OpenCHeck()
     Dim varUser
    Dim varOK
    
    varUser = Environ("username")
    
    varOK = DLookup("racfid", "tbluser", "racfid = """ & varUser & """")
    
    If IsNull(varOK) Then
        MsgBox "Get outa here loser", vbExclamation
        DoCmd.Quit
    End If
 End Function

Thanks you guys for helping!!
 
Did you change how varOK was declared? Only a Variant can hold Null, and unspecified that's what you should get.
 
Ah, glad you got it sorted out.
 
Of course I did change the message box to say something different then get out of here loser. That was just to put something. Thanks again for all of your help!!
 

Users who are viewing this thread

Back
Top Bottom