Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting the 'computers name' from a users computer

Status
Not open for further replies.

Chyld

Programmer
Jul 25, 2001
48
GB
How do I display in a field the users 'computer name' so I can get out of logging in etc?

I gather it is similar to the date or time function
i.e. =Now() or =Date() or even =Time()?

Any takers on this one?

Chyld
 
Thanks for that, only problem is I don't understand all that codey stuff just yet ;-)

I've pasted the module into a new module and saved it as
fOSMachineName

but what do I do then?
 
The answer depends on what you want to do. If you want the computer name to appear in a text box on a form place the following in the Control Source of the text box.

=fOSMachineName()

If you want to use it in a query just place something like the following in the Field Name cell of the query designer.

CompName: fOSMachineName()

You can use it as criteria in a query.

Select * From UserTbl
Where CompName = fOSMachineName()

You can use it to update a table.

Update tbl Set CompName = fOSMachineName()
Where UserID=5

You can use it in VBA code.

If fOSMachineName()='chyld' Then
<do some stuff>
Else
<do different stuff>
End If

Let me know if you have further questions. Terry Broadbent

&quot;The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge.&quot; - Daniel J Boorstin
 
Thanks again, only problem is now I have copied and pasted the contents of the module you pointed me to, but when I change the control source to the '=fOSMachineName()' in the text box in normal mode I just see '?Name'!

Can you help?
 
Did you name the box fOSMachineName? That would cause the ?Name error.
Joe Miller
joe.miller@flotech.net
 
No, I set the control source of the text box to the following:

=fOSMachineName()

As Terry B instructed in an earlier example, it didn't work though.... BOO HOO.

If you could help it would be much appreciated.

Please understand that I am a true beginner in all this and really don't know a lot about VB Programming or SQL etc. Everything I know is self tought...

Chyld.
 

Examine the control source for the text box and make sure the entry has no [] or &quot; around it. It must read exactly

=fOSMachineName()

The () must be included.

Which version of Access are you running? Terry Broadbent

&quot;The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge.&quot; - Daniel J Boorstin
 
Access 2000, yes I have input exactly what you wrote. including the lower and uppercase lettering.

Darn, this is annoying.

I will get there in the end, and when I do, I know it'll be DARN good.

 

Open the module with the function in it. Open the immediate Window. Select View | Immediate Window from the menu. Type

?fOSMachineName()

and press enter. You should see the name of your computer. If you don't, place a breakpoint in the code by clicking on the line that reads &quot;lngLen = 16&quot; and pressing F9.

Go back to the immediate window and run the function again. Use F8 to step through the code one line at a time. Hover the mouse pointer over each variable name to check the value after each step. See if the function and API calls are actually working. Terry Broadbent

&quot;The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge.&quot; - Daniel J Boorstin
 
I don't suppose there is any other way of doing it without the code stuff. I don't understand a single word of what you said there Terry, but thanks for all your help anyway!! LOL

I keep getting :

Compile Error

Expected variable or procedure, not module.

How do I get out of this one?

Chyld
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top