2010-07-14 95 views
3

在Access中开发应用程序。访问文件将位于数据库中,但是当用户需要使用它时,我希望他们将其复制到桌面上。如果他们将它从G:\驱动器(我们的网络文件夹)上运行,它应该给它们一条消息。确定路径是否为网络路径VBA

那么有没有Win API会帮我解决这个问题? 我打算将此代码放置在窗体的Form_Load事件中。

+0

我不能想出你说你想做什么的任何理由。你能解释一下为什么*? – 2010-07-16 00:41:32

回答

1

如果要防止用户打开你的来自G:\驱动器的数据库,您可以使用以下代码在启动表单中进行简单检查:

Dim strMsg As String 
If CurrentProject.Path Like "G:*" Then 
    strMsg = "Please copy this database file to your " & _ 
     "local disk and open the copy instead of this one." 
    MsgBox strMsg 
    Application.Quit 
End If 

如果您还想阻止它们从不同的驱动器号映射或UNC路径打开数据库,则可以将文件(如NotFromHere.txt)添加到存储数据库文件的文件夹中。

Dim strMsg As String 
Dim strFilePath 
strFilePath = CurrentProject.Path & Chr(92) & "NotFromHere.txt" 
If Len(Dir(strFilePath)) > 0 Then 
    strMsg = "Please copy this database file to your " & _ 
     "local disk and open the copy instead of this one." 
    MsgBox strMsg 
    Application.Quit 
End If 
+0

Thankyou的任何想法的替代解决方案。我将采用第二种方式,因为驱动器号可能会更改,所以我不想对其进行硬编码。 – masfenix 2010-07-15 12:50:45

+0

对此的要求已更改,我们确定其不是可行的解决方案。我们要走一条完全不同的路线。谢谢 – masfenix 2010-07-15 14:46:18

0

我认为有一个调用会列出机器上(物理上)连接的驱动器,您可以调用该驱动器并比较用户对列表中的驱动器说明符。

+0

关于它可能被称为 – masfenix 2010-07-14 19:13:54

1

你可能要检查出优秀的访问自动FE更新为复制下来更新等

http://autofeupdater.com/

我滚我自己非常类似的系统之前,我发现这是一个自动化的方式和它确实使得FE更容易更新