Link to home
Start Free TrialLog in
Avatar of mdlp
mdlpFlag for United States of America

asked on

Get the current Computer name in Access VBA

Experts,
In my program I need the current user name and computer name,  Out of the blue I am having computers that fail on my call for the Computer Name.  This is the error that it reports

The expression On Open you entered as the event property produced the following error:  
The form action was canceled the expression may not result in the name of a macro, the name of a user defined function or event Procedures
There may have been an error evaluating the function, event or macro

Computers on the same network work are running correctly, so I think I can rule out any network related issues.  To the best of my knowledge, no MS updates are causing it, even though I suspect it.  All the work stations run the same 2003 Access runtime.    

The code runs in my office and other computers correctly.  I will post the offending code, I have tried 2 different ways to collect the computer name through the function I posted and   Environ$("computername") both fail.
The computer names are not long or any odd characters.  The one I am dealing with is “Wkstn15”

This code has been working for 4+ years and in the last 6 weeks I am having this problem sporadically.  I am at a loss.

Thank you
mdlp

10-0324-ExpertsExchange.txt
SOLUTION
Avatar of kmslogic
kmslogic
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
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
Avatar of Richard Daneke
Could the other workstations be running in 'sandbox' mode and not evaluating an expression outside of access?
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
Avatar of mdlp

ASKER

This is hard, because I got pulled away from my computer, and I did not get to answer you as the answers came in.
DoDahD, I have all my clients on Security Certificates, I am sorry for not making this clear, and actually run the sand box for security and virus issues.
 
KmsLogic, I did not think about the Env….$ pulling from the local environment, but that was not my issue, but it will be stored in memory for future issues.

Jmoss111 and Jdettman, It would appear that the declaration for the Kerne32 was where my problem was, and both of you used the same declaration, which fixed my problem, In fairness Jmoss111 posted first, But I believe the suggestion of a different Dll and the function by JDettman was very good, and if I could award you both full points I would, but to my knowledge, I have to split them.
Thank you again, mdlp