I have a module containing a function copied from the 'net that returns the computer name of the computer using Access 2010 run-time and an Access 2010 accde front end. It works well on all the computers in our LAN except one. On that one computer it causes odd errors such as records with missing data, failure to recognize built in functions such as Left() and crashes when a variable is encountered. Sometimes an error message appears saying there is invalid use of the . (dot) or ! operator or invalid parentheses even though that is not the case. This function actually worked well on this computer until just recently when it started acting up. All the computers on the LAN are 64 bit running Win 10 Pro, some clean installs, some upgraded from Win 7. The code is as follows:
Option Compare Database
Option Explicit
Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
__________________________________________________ _________________
Function 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 If
End Function
I have a similar module that returns the user name. It looks like this:
Option Compare Database
Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
__________________________________________________ ______________
Function 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 = vbNullString
End If
End Function
If I delete the modules and all references to the functions the problems all go away. Any help would be appreciated.