如何检索当前数据库的当前路径? 我有一个AC07程序,分发它我在Intranet服务器上保存一个副本,如何将该程序复制到我们的PC然后使用它? 总是有人直接在服务器上打开文件。从保存在服务器上的文件中检索当前路径
当文件打开后一种形式星自动,在这种形式,我把这个代码:
Private Sub Form_Load()
On Error GoTo ErrorHandler
Dim StrServer As String
StrServer = "\\itbgafs01\Comune\Dashboard\"
If GetDBPath() = StrServer Then
MsgBox "You can't open this file from server" & vbCrLf & _
"save one copy on you PC, and use those", vbCritical, "Dashboard.info"
Application.Quit
End If
Public Function GetDBPath() As String
Dim strFullPath As String
Dim I As Integer
strFullPath = CurrentDb().Name
For I = Len(strFullPath) To 1 Step -1
If Mid(strFullPath, I, 1) = "\" Then
GetDBPath = left(strFullPath, I)
Exit For
End If
Next
End Function
我的问题是:一些PC映射驱动器H:服务器目录,则路径的结果是H:\Comune\Dashboard\
而不是\\itbgafs01\\Dashboard\
。 我如何检索绝对路径? 首先,我想用更多,如果这样的:
Private Sub Form_Load()
On Error GoTo ErrorHandler
Dim StrServer As String
Dim StrMaph As String
StrServer = "\\itbgafs01\Comune\Dashboard\"
StrMaph = "H:\Comune\Dashboard\"
MsgBox StrServer & vbCrLf & _
StrMaph & vbCrLf & _
GetDBPath()
If GetDBPath() = StrServer Or GetDBPath() = StrMaph Then
MsgBox "Non puoi aprire il file sul server" & vbCrLf & _
"copialo sul tuo pC ed avvia il programma da li", vbCritical, "Dashboard.info"
Application.Quit
End If
是否有另一种方式做到这一点?
您可以使用API调用来检索映射驱动器的服务器。但是你现在使用双重检查的方法很简单,所以为什么不坚持呢? – Gustav
@Gustav,是的双重选择的方法是好的,但你知道一个有1000个用户的公司很容易有人在S:或Z:或X上找到服务器目录:......我的是感谢 – Fabrizio
好吧,您只需要命名H驱动器。那么您应该使用API方法 - 就像Cor提供的那样。 – Gustav