Solved #Name? Error in accde file but not in accdb (1 Viewer)

jack555

Member
Local time
Today, 11:56
Joined
Apr 20, 2020
Messages
93
Have two unbound text boxes in a form. Pull the data from a table and filter (using dlookup) based on GetUserName function which I created. The result displayed properly in the accdb file but while in accde file it displays #Name? error. Have to distribute exe file since multiuser environment. Please assist to fix this issue.
 

Minty

AWF VIP
Local time
Today, 07:56
Joined
Jul 26, 2013
Messages
10,355
Have you complied your database code?
 

Minty

AWF VIP
Local time
Today, 07:56
Joined
Jul 26, 2013
Messages
10,355
Can you post up the function and the unbound control source?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:56
Joined
Feb 19, 2013
Messages
16,553
not enough info to suggest anything other than a comment on good practice

to create your .accde the code has to compile. But that does not mean all errors are handled. Before compiling make sure to do the following. Ensure you have Option Explicit at the top of every module below Option Compare Database. Also make sure you are using me. rather than me! - me! can error at runtime as it late binds the variables. Admittedly if it runs in .accdb then it is unlikely, but I have seen instances over the years where this can happen.

Sounds like the issue could be with your function - #Name can occur (not every time) where you have controls with the same name as the controlsource or spaces in field/control names where one of the words is a reserved word e.g. Start Date
 

jack555

Member
Local time
Today, 11:56
Joined
Apr 20, 2020
Messages
93
Thanks for your response. It successfully compiled. Below is the function and what I am trying to get.

Code:
Public Function GetUserName()
    GetUserName = Environ("UserName")
End Function

and below two items are in two unbound text boxes in the form. tried below argument in default value and control source. Both work fine in accdb file but when compiled and made into accde it shows #name error.

=GetUserName()
=DLookUp("department","tblusers","aUsername = '" & GetUserName() & "'")

This is crucial for me since queries depend on this outcome. Please advise
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:56
Joined
Oct 29, 2018
Messages
21,358
Thanks for your response. It successfully compiled. Below is the function and what I am trying to get.

Code:
Public Function GetUserName()
    GetUserName = Environ("UserName")
End Function

and below two items are in two unbound text boxes in the form. tried below argument in default value and control source. Both work fine in accdb file but when compiled and made into accde it shows #name error.

=GetUserName()
=DLookUp("department","tblusers","aUsername = '" & GetUserName() & "'")

This is crucial for me since queries depend on this outcome. Please advise
Hi. Quick question, are you running the accdb and accde files on the same machine?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:56
Joined
Feb 19, 2013
Messages
16,553
also would be a good idea to declare getusername as a string, leaving it as a variant can cause issues

Public Function GetUserName() as string
 

isladogs

MVP / VIP
Local time
Today, 07:56
Joined
Jan 14, 2017
Messages
18,186
I recommend the use of WScript instead of Environ to get user name. See the link in post #9
Also suggest you modify your DLookup to allow for null values
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:56
Joined
Feb 28, 2001
Messages
27,001
I'm trying to piece this together in my mind, and one thing I think is worthy of consideration is to assure that the correct references are defined on the system where the .ACCDE is being run. If you use stuff from the library .DLL files and have a bad reference, sometimes you get that kind of #Name# error because Access can't find the function you named. That's a GUESS but it kind of tickles my memory that such a thing happens sometimes. I believe I have seen that once or twice a long time ago.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:56
Joined
Oct 29, 2018
Messages
21,358
I'm trying to piece this together in my mind, and one thing I think is worthy of consideration is to assure that the correct references are defined on the system where the .ACCDE is being run. If you use stuff from the library .DLL files and have a bad reference, sometimes you get that kind of #Name# error because Access can't find the function you named. That's a GUESS but it kind of tickles my memory that such a thing happens sometimes. I believe I have seen that once or twice a long time ago.
Hi Doc. Great minds think alike. That's why I asked the question earlier and still waiting on the answer. You just said it better than I did. :)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:56
Joined
Feb 28, 2001
Messages
27,001
Well, after all, I AM known for my sesquipedalian pedantry.
 

jack555

Member
Local time
Today, 11:56
Joined
Apr 20, 2020
Messages
93
Thanks for everyone for the reply. Option Explicit solved the problem. Initially it was not resolved but when I tried today with "Option Explicit" working fine as excepted in both accdb and accde file in different machines as well.
 

jack555

Member
Local time
Today, 11:56
Joined
Apr 20, 2020
Messages
93
not enough info to suggest anything other than a comment on good practice

to create your .accde the code has to compile. But that does not mean all errors are handled. Before compiling make sure to do the following. Ensure you have Option Explicit at the top of every module below Option Compare Database. Also make sure you are using me. rather than me! - me! can error at runtime as it late binds the variables. Admittedly if it runs in .accdb then it is unlikely, but I have seen instances over the years where this can happen.

Sounds like the issue could be with your function - #Name can occur (not every time) where you have controls with the same name as the controlsource or spaces in field/control names where one of the words is a reserved word e.g. Start Date

"Option Explicit" solved this problem.
 

Users who are viewing this thread

Top Bottom