Displaying documents within folders
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 239   1
URL.หัวข้อ / URL
Displaying documents within folders

ถามไว้ที่ 
http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_design&Number=108724&Forum=CatSearch-2&Words=TimK&Match=Username&Searchpage=0&Limit=25&Old=allposts&Main=108701&Search=true#Post108724 
 
ดังนี้ 
I am wanting to display a list of files within a drive relating to a specific client. For  
example, in my Db, i want to be able to track to a client (X0001), click a button  
which will display a list of files within folder C:\X0001 in a listbox. When i  
doubleclick on the specific file, i want to be able to open that file.  
 
ต้องการแสดงชื่อไฟล์ต่างๆ ที่เกี่ยวข้องกับลูกค้า เช่น ดูไฟล์ของลูกค้าที่มีรหัส X0001) โดยคลิกที่ปุ่ม แล้วให้แสดงชื่อไฟล์ต่างๆ ของลูกค้าคนนี้ที่อยู่ในห้อง C:\X0001 ใน listbox และเมื่อคลิก 2ทีที่ชื่อไฟล์ให้เปิดไฟล์ดังกล่าวขึ้นมาด้วย 
 
ผมตอบให้เขาใช้โค้ดดังนี้ครับ 
 
Private Function fnGetList() As String 
 
    Dim objFS As Object, objFolder As Object 
    Dim objFiles As Object, objF1 As Object 
    Dim strFill As String, strFolderPath As String 
    Dim TempString As String 
     
    strFolderPath = "h:/" & Me.ClientID 
     
    If Dir(strFolderPath, vbDirectory) = "" Then 
        MsgBox "The path is not valid", vbOKOnly, "Not Found" 
        Exit Function 
    End If 
     
    Set objFS = CreateObject("Scripting.FileSystemObject") 
    Set objFolder = objFS.GetFolder(strFolderPath) 
    Set objFiles = objFolder.files 
         
    For Each objF1 In objFiles 
        TempString = TempString & objF1.Name & ";" 
    Next 
    Debug.Print TempString 
     
    Set objF1 = Nothing 
    Set objFiles = Nothing 
    Set objFolder = Nothing 
    Set objFS = Nothing 
  
    Me.List2.RowSource = TempString 
     
End Function 
 
Private Sub ClientID_AfterUpdate() 
    fnGetList 
    Me.List2.Requery 
End Sub 
 
Private Sub Form_Load() 
Me.List2.RowSourceType = "Value List" 
End Sub 
 
Private Sub List2_DblClick(Cancel As Integer) 
    Dim strFile As String 
    strFile = "h:\" & Me.ClientID & "\" & Me.List2 
    'StartDoc strFile 
    FollowHyperlink strFile 
End Sub  *** Edited by Supap Chaiya *** 3/9/2546 21:48:53

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R00580
ผมเจอบทความเกี่ยวกับเรื่องนี้ที่ http://support.microsoft.com/default.aspx?scid=kb;en-us;q308634 เป็นวิธีการอีกรูปแบบหนึ่ง ซึ่งน่านำมาศึกษาดูด้วยครับ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0501s