Selasa, 06 Maret 2018

Re: [MS_AccessPros] Deriving a file name from a list box item

 

Art, 
You should be able to change your code as noted:

 If IsNull(DLookup("DocumentLocation", "tblDocuments", "DocumentLocation = '" & strDocLoc & "'")) Then
    rs.AddNew
    rs!DocumentNAme = Mid(strDocLoc, InstrRev(strDocLoc, "\")+1)
    rs!DocumentLocation = strDocLoc


Notice I have used the strDocLoc rather than continually grabbing from the FileList control.

Duane Hookom


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
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
 


I have a listbox control that is set up as a Value List and is populated by the following code in a command button called cmdGetFiles:

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)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar