gpt4 book ai didi

forms - 将文件浏览器按钮添加到MS Access表单

转载 作者:行者123 更新时间:2023-12-04 03:40:31 24 4
gpt4 key购买 nike

我想在MS Access 2007表单中添加一个“浏览”按钮,它将弹出一个标准的Windows文件浏览器(作为模式窗口)并允许用户选择目录。当用户从该浏览器中退出时,应将所选目录的路径写入“Access ”表单中的文本框中。

最好的方法是什么?有 native Access 方法吗?

最佳答案

创建一个使用Application.FileDialog的函数。 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

我认为您可以在命令按钮的click事件中使用该功能。

Dim strChoice As String
strChoice = FolderSelection
If Len(strChoice) > 0 Then
Me.TextBoxName = strChoice
Else
' what should happen if user cancelled selection?
End If

如果您担心微软有朝一日可能会从Office中删除 FileDialog对象,则可以改用Windows API方法: BrowseFolder Dialog

关于forms - 将文件浏览器按钮添加到MS Access表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6203852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com