如何从对话框浏览器中保存文本框中的文件位置

时间:2014-07-10 09:32:50

标签: access-vba ms-access-2010

我已经编写了以下代码来尝试打开文件浏览器,然后将文件位置保存到文本框中。到目前为止,我可以打开文件浏览器,但无法将其保存到我的文本框

Private Sub txtImageName_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

1 个答案:

答案 0 :(得分:0)

将文件夹和文件保存到文本框:

Private Sub txtImageName_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
        Me.YourTextbox = strFolder & "\" & strFile <<<<<<<<<<<<<<<< ADD THIS LINE
    Next
  End If
  Set f = Nothing
End Sub