มีวิธีที่ Import Text อื่นหรือไม่นอกจาก
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 379   3
URL.หัวข้อ / URL
มีวิธีที่ Import Text อื่นหรือไม่นอกจาก

คือตอนนี้ผมใช้ Wizard อยู่ครับ 
DoCmd.TransferText acImportFixed, "Ddp016 Import Specification", "TOrder", Me![DirPath], False, ""

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

1 @R00525
ลองดูโค้ดข้างล่างครับ Sub LinkText() Dim dbs As Database Dim tdfSales As TableDef Dim rstSales As Recordset ' Open the Microsoft Access database. Set dbs = CurrentDb ' Create a TableDef object. Set tdfSales = dbs.CreateTableDef("Linked Text Table") ' Set the connection string to specify the source database type and ' the full path to the file that contains the table you want to link. tdfSales.Connect = "Text;" _ & "DATABASE=C:\Documents and Settings\kaeg\My Documents" ' Set the SourceTableName property to the name of the table you want to access. tdfSales.SourceTableName = "test.txt" ' Append the TableDef object to the TableDefs collection to create a link. dbs.TableDefs.Append tdfSales End Sub เป็นการ Link ไฟล์ Text เข้ามาใน Access ครับ
2 @R00526
ผมดูแล้วไม่คอยเข้าใจครับ คุณสุภาพช่วยอธิบายหน่อยได้ไหมครับ สมมุติว่า Text File ชื่อ C:\Database\ABCD.txt แล้วจะกำหนดได้ยังไงครับว่า ให้ ตัวที่ 1-10 อยู่ใน ฟิลฟ์ที่1, 11-20 อยู่ในฟิลฟ์ที่ 2
3 @R00528
โค้ดข้างบนจะเป็นการ link แบบ Delimited คือมีอะไรเป็นตัวแบ่งข้อมูลแต่ละฟีลด์ครับ ... tdfSales.Connect = "Text;" _ & "DATABASE=C:\Database\" ' Set the SourceTableName property to the name of the table you want to access. tdfSales.SourceTableName = "ABCD.txt" ... ถ้าไฟล์ Text เป้าหมายเป็นแบบ Fixed ก็คงต้องมี Specification ก่อน แต่ว่าลองทำตามคำแนะนำของผมในคำถามก่อนของคุณที่ http://www.thai-access.com/suphap.php?topic_id=264 ดูก่อนนะครับ อาจจะแก้ปัญหาเก่าได้
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0445s