需要在Access窗体上使用My.Computer.Name,但它会导致424运行时错误("需要对象")。我从Microsoft的Office Dev网站复制并粘贴了My.Computer.Name的示例代码,该代码生成相同的运行时错误。我也尝试了具有相同结果的My.Computer.FileSystem.DirectoryExists。
非常感谢任何帮助!
答案 0 :(得分:1)
基本上,使用
'more simple but easier to "spoof"
Environ("computername")
'Should use as long as it works on your Access server
'Simply call "ComputerName()" whenever you need to get the user's computer
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, ByRef nSize As Long) As Long
Function ComputerName() As String
Dim stBuff As String * 255
Dim lAPIResult As Long
Dim lBuffLen As Long
lBuffLen = 255
lAPIResult = GetComputerName(stBuff, lBuffLen)
If lBuffLen > 0 Then
ComputerName = Left(stBuff, lBuffLen)
End If
End Function