wedd
10-27-2010, 02:20 AM
I wrote the following code to retrieve a username and computer name for the access 2007 databse I created. I see a #Name? error appearing. Are there any reasons why this error appears as the code seems to be correct.:dunno
Thanks for your ideas :clap:
modUserName
Option Compare Database ' This code was originally written by Dev Ashish.' It is not to be altered or distributed,' except as part of an application.' You are free to use it in any application,' provided the copyright notice is left unchanged.'' Code Courtesy of Dev Ashish at The Access Web (http://www.mvps.org/access/)Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As LongFunction fOSUserName() As String' Returns the network login name Dim lngLen As Long, lngX As Long Dim strUserName As String strUserName = String$(254, 0) lngLen = 255 lngX = apiGetUserName(strUserName, lngLen) If lngX <> 0 Then fOSUserName = Left$(strUserName, lngLen - 1) Else fOSUserName = "" End IfEnd Function
modComputerName
Option Compare Database ' This code was originally written by Dev Ashish.' It is not to be altered or distributed,' except as part of an application.' You are free to use it in any application,' provided the copyright notice is left unchanged.'' Code Courtesy of Dev AshishPrivate Declare Function apiGetComputerName Lib "kernel32" Alias _"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongFunction fOSMachineName() As String'Returns the computername Dim lngLen As Long, lngX As Long Dim strCompName As String lngLen = 16 strCompName = String$(lngLen, 0) lngX = apiGetComputerName(strCompName, lngLen) If lngX <> 0 Then fOSMachineName = Left$(strCompName, lngLen) Else fOSMachineName = "" End IfEnd Function
Thanks for your ideas :clap:
modUserName
Option Compare Database ' This code was originally written by Dev Ashish.' It is not to be altered or distributed,' except as part of an application.' You are free to use it in any application,' provided the copyright notice is left unchanged.'' Code Courtesy of Dev Ashish at The Access Web (http://www.mvps.org/access/)Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As LongFunction fOSUserName() As String' Returns the network login name Dim lngLen As Long, lngX As Long Dim strUserName As String strUserName = String$(254, 0) lngLen = 255 lngX = apiGetUserName(strUserName, lngLen) If lngX <> 0 Then fOSUserName = Left$(strUserName, lngLen - 1) Else fOSUserName = "" End IfEnd Function
modComputerName
Option Compare Database ' This code was originally written by Dev Ashish.' It is not to be altered or distributed,' except as part of an application.' You are free to use it in any application,' provided the copyright notice is left unchanged.'' Code Courtesy of Dev AshishPrivate Declare Function apiGetComputerName Lib "kernel32" Alias _"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongFunction fOSMachineName() As String'Returns the computername Dim lngLen As Long, lngX As Long Dim strCompName As String lngLen = 16 strCompName = String$(lngLen, 0) lngX = apiGetComputerName(strCompName, lngLen) If lngX <> 0 Then fOSMachineName = Left$(strCompName, lngLen) Else fOSMachineName = "" End IfEnd Function