Link to home
Start Free TrialLog in
Avatar of Bob Schneider
Bob SchneiderFlag for United States of America

asked on

Recognize PC Name in VB6

I have an app that was written in vb6 years ago.  I use the app on several different machines and I am wondering if there is a way that I can get it to recognize the name of the pc so I can access the sql server 2008 database regardless of which machine I am running it on (ie: "\PCName\SQLExpress".  Or better yet, get at the local db without making a machine reference at all.

Thanks~
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

This works in Access 2010 VBA.

'Add the below API call to the general declarations section of any code module

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

'Then add this to call the API function.  Modify the naming convention to suit your needs.

Dim str_computer_name As String, lng_buffer_size As Long, lng_ret_code As Long, lng_null_character_position As Long

str_computer_name = Space(80)
lng_buffer_size = Len(str_computer_name)

lng_ret_code = GetComputerName(str_computer_name, lng_buffer_size)

lng_null_character_position = InStr(str_computer_name, Chr(0))
If lng_null_character_position > 0 Then
    str_computer_name = Left(str_computer_name, lng_null_character_position - 1)
Else
    str_computer_name = " "
End If
Avatar of HooKooDooKu
HooKooDooKu

Can you just put the SQL DB on a network drive and have everyone access the same database?
Avatar of Bob Schneider

ASKER

We use the software in remote locations that are not on a network.  I will look at the previous solution.  It looks like it might work.  The only way to do something like "App.Path" would be to put the db in the same directory as the compiled application, right?
ASKER CERTIFIED SOLUTION
Avatar of shorvath
shorvath
Flag of Canada 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
Great!  Thanks!!