Need help on VB code to identify TS name

N

NEWBIE

Not sure this is the correct group to ask.
I created a program in MS Access to perform specific queries for a specific
computer or TS client but need sample code on how to validate the name of the
TS client in order to run appropriate queries for that specific TS client. I
know how to
identify the name of the computer if it's a regular computer but for TS
clients, it only returns the name of the server and not the specific TS unit.

I am intermediate MS Access user and have written lots of programs but only
know
very minimal VB coding.

Thanks in advance for help!
 
N

NEWBIE

Thanks Albert for the quick response and help!
I will go check this out and let you know.
 
N

NEWBIE

Albert,

I just checked the site you gave me and unfortunately the
script listed does not help me for identifying unique terminal server units.
I tried this script already and it will only return the name of the SERVER
and not
the specific terminal client. We have many TS units in the company and I
want to
identify the specific hardware unit and not the mother server.
:((((
 
N

NEWBIE

Hi again Albert,

I was given the following script to try (that is supposed to identify the
terminal client unit name) but I keep getting the error "Only comments can
appear after End Sub, etc...).
I am not sure how to resolve the error. I think this script may do what I
need if I can figure out the error. Thanks for any help you can offer in
advance!



'//Declare API Function Declarations from Kernel32 DLL
Declare Function GetEnvironmentVariableA Lib "kernel32" ( _
ByVal lpName As String, _
ByVal lpBuffer As String, _
ByVal nsize As Long) As Long

'Returns Client Computer Name by retrieving 32bit environment variable.
Private Function GetClientComputerName() As String

Dim lStringLength As Long 'Len of String
Dim sEnv As String ''' buffer To hold environment string

'Allocate space for Dos Environment String.
sEnv = Space(4096)

'Get data for given environment variable.
lStringLength = GetEnvironmentVariableA("CLIENTNAME", sEnv, 4096)

'Pull value based on lpszenv length.
GetClientComputerName = Left(sEnv, lStringLength)


End Function
 
N

NEWBIE

Not sure if you got this message before, it crashed on me.
I got this VB script to try that will supposedly give me the terminal server
unit name but I can't figure out how to resolve the error message that I keep
getting
"Only comments may appear after End Sub, etc....".
Could you advise? Thanks in advance for your help!


'//Declare API Function Declarations from Kernel32 DLL
Declare Function GetEnvironmentVariableA Lib "kernel32" ( _
ByVal lpName As String, _
ByVal lpBuffer As String, _
ByVal nsize As Long) As Long

'Returns Client Computer Name by retrieving 32bit environment variable.
Private Function GetClientComputerName() As String

Dim lStringLength As Long 'Len of String
Dim sEnv As String ''' buffer To hold environment string

'Allocate space for Dos Environment String.
sEnv = Space(4096)

'Get data for given environment variable.
lStringLength = GetEnvironmentVariableA("CLIENTNAME", sEnv, 4096)

'Pull value based on lpszenv length.
GetClientComputerName = Left(sEnv, lStringLength)


End Function
 
A

Albert D.Kallal

Albert,

I just checked the site you gave me and unfortunately the
script listed does not help me for identifying unique terminal server
units.
I tried this script already and it will only return the name of the SERVER
and not

Well, of course the computer name is always going to be the name of the
server, so the one you want is:
I mean, surely, all users don't log on using the same id...do they? (that is
a incorrect setup for ms-access by the way, as EACH user needs their OWN
copy of the Front end..and even when you use TS, you must do this). So,
should not grabbing the user logon id be ok?

I don't know if you can actually pick up the computer name, as you can
actually use TS through a web browser. So, you can certainly pick up the
logon user name with above, and I kind of thought that would be good enough.
However, grabbing the client computer name? Hum, just don't know on that
one. Any reason why you can't/don't use the user logon name?
 
N

NEWBIE

Hi Albert,
Thanks for the response, I didn't see it till now.
The reason I can't use the user logon name is because each location that the
TS terminal is at represents a specific department that the user needs to
scan in
data to (ex: Test department, Final Inspection department). To avoid needing
to
prompt the user for a department code, I have set up my program to
automatically
take the user's scanned data (employee# and product serial#) and link it
with the
department code (in this case the specific ID of the TS unit). I have a
cross reference table that says if TS ID =X, then assign the input data code
to department X, if TS ID=y, assign data to y, etc....
Since this is a fast paced production environment, I am trying to limit the
user input to only his emloyee# and product serial#.
Thanks again for your continued responses! Again I am not a VB programmer
and only know very limited VB. I was told the code I showed you would do this
but I keep running into the error message "Only comments after Sub End...etc".
Thanks! I hope you can help.
 
A

Albert D.Kallal

but I keep running into the error message "Only comments after Sub
End...etc".
Thanks! I hope you can help.

I would remove all your old stuff and try again.

Further to accomplish this, you likely should create a new module.

on the modules tab, go new

You are jumped into a new module

You should see:

Option Compare Database
Option Explicit

so, right after the above, you paste in the code from here

http://www.mvps.org/access/api/api0008.htm

Now, go file->save (answer yes to save the modules)

At this point, you now should be able to use anywhere in your code a
fucntion called:

fOsUserName()

Try using the above in the debug window (just hit ctrl-g, and in the debug
(imeediate) window, type in

? fOsUsesrName()

It should return your logged on name.
 
Top