Duane Hookom
Sent: Tuesday, March 6, 2018 2:44 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Deriving a file name from a list box item
Private Sub cmdGetFiles_Click()
Dim fDialog1 As Office.FileDialog
Dim varFile1 As Variant
' Clear listbox contents. '
Me.FileList.RowSource = ""
' Set up the File Dialog. '
Set fDialog1 = Application.FileDialog(msoFileDialogFilePicker)
With fDialog1
' Allow user to make multiple selections in dialog box '
.AllowMultiSelect = True
' Set the title of the dialog box. '
.Title = "Please select one or more files"
' Clear out the current filters, and add our own.'
.Filters.Clear
.Filters.Add "PDF Files", "*.pdf"
.Filters.Add "Word Documents", "*.Doc*"
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the '
' user picked at least one file. If the .Show method returns '
' False, the user clicked Cancel. '
If .Show = True Then
'Loop through each file selected and add it to our list box. '
For Each varFile1 In .SelectedItems
Me.FileList.AddItem varFile1
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
This populated the FileList list box. I now have a command button called cmdImport:
Private Sub cmdImport_Click()
Dim db As Database
Dim rs As Recordset
Dim iRecCount As Integer
Dim strDocLoc As String
Dim intI As Integer
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblDocuments")
iRecCount = Me.FileList.ListCount
For intI = 0 To Me.FileList.ListCount - 1
strDocLoc = Me.FileList.ItemData(intI)
Debug.Print strDocLoc
If IsNull(DLookup("DocumentLocation", "tblDocuments", "DocumentLocation = '" & FileList.ItemData(intI) & "'")) Then
rs.AddNew
rs!DocumentNAme =
rs!DocumentLocation = FileList.ItemData(intI)
rs!DocumentKey = gUserID + gintCabinetName + gintFolderID + gintSubFolderID + Format(Now, "yyyy-mm-dd hh-mm")
rs!CreatedDate = Now()
rs!CreatedByUserID = glngThisEmpID
'rs!DOCUSER_ID = glngThisEmpID
rs!DocumentFileType = FileExtensionFromPath(FileList.ItemData(intI))
'rs!ACTIVE = -1
rs.Update
End If
Next intI
MsgBox "You have imported " & CStr(iRecCount) & " records.", vbOKCancel
rs.Close
Set rs = Nothing
Set db = Nothing
Me!sfrmDocumentList.Form.Requery
Me.FileList.RowSource = ""
End Sub
I need to grab just the file name from the listbox and pass it into my addnew.
rs!DocumentName =
The items in the list box contain the path as well as the file name and all i need to is the filename and extension to pass into the database,
This is a sample of what is in the listbox.
C:\Work\MSP-in-10-weeks.pdf
C:\Work\Helpdesk Database Structure 270.pdf
C:\Work\HMIS-Data-Dictionary.pdf
Thank you
Art Lorenzini
Sioux Falls, SD
Posted by: Duane Hookom <duanehookom@hotmail.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (2) |
Tidak ada komentar:
Posting Komentar