Get Computername in VBA?

D

Dave Reardon

I am attempting to retrieve the computername within an Access database, so
that in the event of an error, it can email the probem, with the computer
name to help identify the problem. I am relatively new to VBA, having coded
most things in Macros before. Is there a variable I can call that holds the
current computer name and username, a bit like (SUSER_SNAME()) and
(HOST_NAME()) in SQL server please?

Thanks in anticipation

Dave
 
B

bcap

Or you could simply use the environment variables:

environ("COMPUTERNAME")
environ("USERNAME")
 
B

Bob Quintal

I gave you an example where any human could tell the environment
variable method was unreliable for getting the user name and
computer name, but the code couldn't. Sorry if you didn't get
that part of the message.

Chris

The environ() function is not sufficiently reliable to protect State
Secrets from a determined spy, but is more than reliable enough for
the original poster's stated application.

"so that in the event of an error, it can email the probem, with the
computer name to help identify the problem."

Q
This is already more of a reply than such a stupid post warrants.
Environment variables are untrustworthy. If your code checked
those variables and found user BarackObama on computer AirForce1
on your network
[quoted text clipped - 6 lines]
environ("COMPUTERNAME")
environ("USERNAME")
 
D

Douglas J. Steele

Bob Quintal said:
The environ() function is not sufficiently reliable to protect State
Secrets from a determined spy, but is more than reliable enough for
the original poster's stated application.

"so that in the event of an error, it can email the probem, with the
computer name to help identify the problem."

While that's true, Bob, a user who doesn't want to be identified can very
easily circumvent things so that the original poster's aim would not be met.

Why not use the API calls in http://www.mvps.org/access/api/api0008.htm and
http://www.mvps.org/access/api/api0009.htm at "The Access Web" and eliminate
that possiblity?
 
B

Bob Quintal

While that's true, Bob, a user who doesn't want to be identified
can very easily circumvent things so that the original poster's
aim would not be met.

Why not use the API calls in
http://www.mvps.org/access/api/api0008.htm and
http://www.mvps.org/access/api/api0009.htm at "The Access Web" and
eliminate that possiblity?

I do use them for logging users to an audit trail, and assigning
supervisory rights. However if I needed to debug some issue, would I
want to add a whole module, or two, of untested (in the app, I'm sure
the code you point to is pretty robust) to aid in debugging?
If the code is already there, or if there are no current problems,
I'd probably use the API calls. But even those can be worked around
by a determined saboteur.

"Horses for courses" is an old saw, but still valid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top