确定路径是否是网络路径VBA

时间:2010-07-14 19:07:22

标签: ms-access access-vba

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

那么Win API会帮助我解决这个问题吗? 我将把这段代码放在表单的Form_Load事件中。

4 个答案:

答案 0 :(得分:1)

您可以使用FileSystemObject DriveType属性

http://msdn.microsoft.com/en-us/library/ea5ht6ax(VS.85).aspx

如果您需要桌面文件夹,可以查看:

CreateObject("WScript.Shell").SpecialFolders("Desktop")

答案 1 :(得分: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

答案 2 :(得分:1)

您可能希望查看优秀的访问自动FE更新程序,作为复制更新等的自动方式

http://autofeupdater.com/

在我找到这个系统之前,我已经完成了我自己非常相似的系统,它确实使得更新FE更加容易

答案 3 :(得分:0)

我认为有一个调用会在机器上列出(物理上)连接的驱动器,你可以调用它并比较用户给出的路径上的驱动器说明符。