CreganTur
11-12-2008, 12:59 PM
I'm currently working through the Wrox book Expert Access 2007 Programming. Unfortunately, I'm doing this in Access 2003 :whistle: (no access to Access 2007 at work).
Most of the book seems to be generic, so I'm able to work through the examples without any issues... except for this one.
Below is the code for an API call that should return the Computer Name, and the format of the returned name is defined when the function is called, via the Enum.
I cannot get this to work at all. I even got the code from the site and C&Ped it, but still no dice. Could someone with Access 2007 test this for me and tell me if it works? Paste it into a new module and in the Immediate Window type: "?GetComputerNameHelper(" without the quotes, naturally. After you type the opening parantheses the options declared in the Enum should appear. Choose one, close the parantheses and hit enter- it should return your computer name.
If it doesn't work then it means there's something wrong with the example.
Option Compare Database
Option Explicit
Public Declare Function GetComputerNameEx Lib "kernel32.dll" Alias "GetComputerNameExA" ( _
ByVal NameType As COMPUTER_NAME_FORMAT, _
ByVal lpBuffer As String, _
ByRef lpnSize As Long) As Long
Public Enum COMPUTER_NAME_FORMAT
ComputerNameNetBIOS
ComputerNameDnsHostname
ComputerNameDnsDomain
ComputerNameDnsDillyQualified
ComputerNamePhysicalNetBIOS
ComputerNamePhysicalDnsHostname
ComputerNamePhysicalDnsDomain
ComputerNamePhysicalDnsFullyQualified
ComputerNameMax
End Enum
Private Function GetComputerNameHelper(NameType As COMPUTER_NAME_FORMAT) As String
Dim buffer As String 'space to receive data
Dim rc As Long 'return code
Dim pSize As Long 'pointer to a long- number of characters returned by function
'allocate some space
buffer = Space(255)
pSize = Len(buffer)
'return data
If (GetComputerNameEx(NameType, buffer, pSize)) Then
GetComputerNameHelper = Trim(Left(buffer, pSize))
End If
End Function
Most of the book seems to be generic, so I'm able to work through the examples without any issues... except for this one.
Below is the code for an API call that should return the Computer Name, and the format of the returned name is defined when the function is called, via the Enum.
I cannot get this to work at all. I even got the code from the site and C&Ped it, but still no dice. Could someone with Access 2007 test this for me and tell me if it works? Paste it into a new module and in the Immediate Window type: "?GetComputerNameHelper(" without the quotes, naturally. After you type the opening parantheses the options declared in the Enum should appear. Choose one, close the parantheses and hit enter- it should return your computer name.
If it doesn't work then it means there's something wrong with the example.
Option Compare Database
Option Explicit
Public Declare Function GetComputerNameEx Lib "kernel32.dll" Alias "GetComputerNameExA" ( _
ByVal NameType As COMPUTER_NAME_FORMAT, _
ByVal lpBuffer As String, _
ByRef lpnSize As Long) As Long
Public Enum COMPUTER_NAME_FORMAT
ComputerNameNetBIOS
ComputerNameDnsHostname
ComputerNameDnsDomain
ComputerNameDnsDillyQualified
ComputerNamePhysicalNetBIOS
ComputerNamePhysicalDnsHostname
ComputerNamePhysicalDnsDomain
ComputerNamePhysicalDnsFullyQualified
ComputerNameMax
End Enum
Private Function GetComputerNameHelper(NameType As COMPUTER_NAME_FORMAT) As String
Dim buffer As String 'space to receive data
Dim rc As Long 'return code
Dim pSize As Long 'pointer to a long- number of characters returned by function
'allocate some space
buffer = Space(255)
pSize = Len(buffer)
'return data
If (GetComputerNameEx(NameType, buffer, pSize)) Then
GetComputerNameHelper = Trim(Left(buffer, pSize))
End If
End Function