如何从 VBA 中的文件对话框对象中获取单个文件名(对于 MS Access 2007)?
如何更改代码以获取文件名而不是目录名? openDialog.InitialFilename
给我目录名称。openDialog.FileName
给我错误“找不到方法或数据成员”。
Private Sub btnEditPhoto_Click()
If (txtImageName > "") Then
Application.FollowHyperlink txtImageName
Else
Dim openDialog As Office.FileDialog
Set openDialog = Application.FileDialog(msoFileDialogFilePicker)
openDialog.Filters.Clear
openDialog.Filters.Add "JPEG Files", "*.jpg"
Dim pickedFile As Boolean
pickedFile = openDialog.Show
If pickedFile Then
txtImageName.SetFocus
txtImageName.Text = openDialog.InitialFileName
End If
End If
End Sub
How do I change my code to get the file name instead of the directory name? openDialog.InitialFilename
gives me the directory name.openDialog.FileName
gives me the error "Method or data member not found".
Private Sub btnEditPhoto_Click()
If (txtImageName > "") Then
Application.FollowHyperlink txtImageName
Else
Dim openDialog As Office.FileDialog
Set openDialog = Application.FileDialog(msoFileDialogFilePicker)
openDialog.Filters.Clear
openDialog.Filters.Add "JPEG Files", "*.jpg"
Dim pickedFile As Boolean
pickedFile = openDialog.Show
If pickedFile Then
txtImageName.SetFocus
txtImageName.Text = openDialog.InitialFileName
End If
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您想要:
代替:
因为您不允许多重选择。
所以:
如果使用AllowMultiSelect,则需要迭代SelectedItems
You want:
In place of:
As you have not allowed multiselect.
So:
If AllowMultiSelect is used, you need to iterate through SelectedItems
我需要选择一个文本文件...这就是我所做的...它工作得很好。
另外...您可以将对话框类型替换为...
并且它同样有效。
I needed to select a single text file... this is what I did... it worked fine.
Additionally... you can replace the dialog type with...
and it worked equally well.