office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

access組閤框行來源加載txt文本的數據

2020-07-09 08:00:00
tmtony8
原創
3327

在access數據庫中,我們不僅可以讀取access創建的數據錶上的數據,還是能讀取TXT文本上的數據

如創建一箇1.TXT的文本文件,裡麵填寫幾箇值,用分號隔開


在窗體的加載事件中添加以下代碼,主要是通過創建FileSystemObject對象,把TXT文本的數據作爲組閤框的行來源,組閤框的行來源類型設置爲“值列錶”

    Dim ObjFile As Object
    Dim myFile As Object
    Set ObjFile = CreateObject("Scripting.FileSystemObject")
    Set myFile = ObjFile.OpenTextFile(CurrentProject.Path & "\1.txt", 1)
    txt1.RowSourceType = "Value List" 
    txt1.RowSource = myFile.ReadLine    '賦值到組閤框    
    myFile.Close
    Set ObjFile = Nothing
    Set myFile = Nothing


穫取效果如圖:

    分享