浏览并获取图像路径,然后将选择加载到 Access 表单中的文本框中
Browse for and get path for image then have selection loaded into text box in Access form
我正在使用 HansUp 的代码:
Private Sub Command7_Click()
Dim f As Object
Dim strFile As String
Dim strFolder As String
Dim varItem As Variant
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
If f.Show Then
For Each varItem In f.SelectedItems
strFile = Dir(varItem)
strFolder = Left(varItem, Len(varItem) - Len(strFile))
MsgBox "Folder: " & strFolder & vbCrLf & _
"File: " & strFile
Next
End If
Set f = Nothing
End Sub
但是,我希望将我选择的绝对路径放入文本框而不是弹出窗口 window。
边学边学。
我不明白为什么会出现错误 438,所以只编写并测试了这个版本。
我的命令按钮名为 cmdBrowse,我存储所选文件路径的文本框名为 MyTextBox.
Private Sub cmdBrowse_Click()
Const msoFileDialogFilePicker As Long = 3
Dim f As Object
Set f = Application.FileDialog(msoFileDialogFilePicker)
f.AllowMultiSelect = False
If f.Show Then
MsgBox f.SelectedItems(1)
'Me!MyTextBox.Value = f.SelectedItems(1)
End If
Set f = Nothing
End Sub
验证 MsgBox
正确显示文件路径后,禁用该行并启用下一行:
'MsgBox f.SelectedItems(1)
Me!MyTextBox.Value = f.SelectedItems(1)
我正在使用 HansUp 的代码:
Private Sub Command7_Click()
Dim f As Object
Dim strFile As String
Dim strFolder As String
Dim varItem As Variant
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
If f.Show Then
For Each varItem In f.SelectedItems
strFile = Dir(varItem)
strFolder = Left(varItem, Len(varItem) - Len(strFile))
MsgBox "Folder: " & strFolder & vbCrLf & _
"File: " & strFile
Next
End If
Set f = Nothing
End Sub
但是,我希望将我选择的绝对路径放入文本框而不是弹出窗口 window。
边学边学。
我不明白为什么会出现错误 438,所以只编写并测试了这个版本。
我的命令按钮名为 cmdBrowse,我存储所选文件路径的文本框名为 MyTextBox.
Private Sub cmdBrowse_Click()
Const msoFileDialogFilePicker As Long = 3
Dim f As Object
Set f = Application.FileDialog(msoFileDialogFilePicker)
f.AllowMultiSelect = False
If f.Show Then
MsgBox f.SelectedItems(1)
'Me!MyTextBox.Value = f.SelectedItems(1)
End If
Set f = Nothing
End Sub
验证 MsgBox
正确显示文件路径后,禁用该行并启用下一行:
'MsgBox f.SelectedItems(1)
Me!MyTextBox.Value = f.SelectedItems(1)