我想向 MS Access 2007 表单添加一个“浏览”按钮,该按钮将打开标准 Windows 文件浏览器(作为模式窗口)并允许用户选择目录。当用户确定退出该浏览器时,所选目录的路径应写入 Access 表单中的文本框。
最好的方法是什么?有没有原生的Access方式?
创建一个函数,使用Application.FileDialog
. The FileDialog
是模态的。
如果用户创建了一个文件夹,此函数将返回用户的文件夹选择;如果用户单击了“取消”,则返回一个空字符串。FileDialog
.
Public Function FolderSelection() As String
Dim objFD As Object
Dim strOut As String
strOut = vbNullString
'msoFileDialogFolderPicker = 4
Set objFD = Application.FileDialog(4)
If objFD.Show = -1 Then
strOut = objFD.SelectedItems(1)
End If
Set objFD = Nothing
FolderSelection = strOut
End Function
我认为您可以在命令按钮的单击事件中使用该函数。
Dim strChoice As String
strChoice = FolderSelection
If Len(strChoice) > 0 Then
Me.TextBoxName = strChoice
Else
' what should happen if user cancelled selection?
End If
如果您担心 Microsoft 可能会删除FileDialog
有一天,您可以使用 Windows API 方法来代替 Office 中的对象:浏览文件夹对话框 http://access.mvps.org/access/api/api0002.htm.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)