Hello, I feel like this is a relatively easy answer, but no amount of searching has lead me to the answer.
I have the above listed code, which works. Ultimately the user selects the folder where "import.csv" is located and the data is imported. I would like to change this so the user can select the file, in cases where the user does not name the file "import.csv". I am confused as to how I would make the bold part above pull out the file name when the file is selected. I have my cmdSelectFile built already (listed below).Private Sub cmdSelectFolder_Click() Dim fDialog As FileDialog, result As Integer Set fDialog = Application.FileDialog(msoFileDialogFolderPicker) fDialog.AllowMultiSelect = False fDialog.Title = "Select folder" If fDialog.Show = -1 Then Debug.Print fDialog.SelectedItems(1) End If ep = fDialog.SelectedItems(1) Me.DirectoryName.Value = ep End Sub Private Sub cmdImport_Click() directory = DirectoryName FileName = "import.csv" Set rs = CreateObject("ADODB.Recordset") strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & directory & ";" _ & "Extended Properties=""text;HDR=Yes;FMT=Delimited"";" strSQL = "SELECT * FROM " & FileName rs.Open strSQL, strconn, 3, 3 rs.MoveFirst Do frmBook.FIRSTNAME.Value = rs("FirstName") frmBook.LASTNAME.Value = rs("LastName") frmBook.MIDDLENAME.Value = rs("MiddleName") End If rs.MoveNext Loop Until rs.EOF Unload Me End Sub
Thank you in advanced for any help given.Private Sub cmdSelectFile_Click() With Application.FileDialog(msoFileDialogFilePicker) .AllowMultiSelect = False 'Single File Select .Filters.Add "CSV Files", "*.csv", 1 'CSV Files Only .Show 'Show File Select Me.FileName.Value = .SelectedItems.Item(1) 'Store Path in Field End With End Sub




