office交流網(wǎng)--QQ交流群號(hào)及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

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

微信交流群(請(qǐng)用微信掃碼)

        

access組合框行來(lái)源加載txt文本的數(shù)據(jù)

2020-07-09 08:00:00
tmtony8
原創(chuàng)
3850

在access數(shù)據(jù)庫(kù)中,我們不僅可以讀取access創(chuàng)建的數(shù)據(jù)表上的數(shù)據(jù),還是能讀取TXT文本上的數(shù)據(jù)

如創(chuàng)建一個(gè)1.TXT的文本文件,里面填寫(xiě)幾個(gè)值,用分號(hào)隔開(kāi)


在窗體的加載事件中添加以下代碼,主要是通過(guò)創(chuàng)建FileSystemObject對(duì)象,把TXT文本的數(shù)據(jù)作為組合框的行來(lái)源,組合框的行來(lái)源類型設(shè)置為“值列表”

    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


獲取效果如圖:

    分享
    文章分類
    聯(lián)系我們
    聯(lián)系人: 王先生
    Email: 18449932@qq.com
    QQ: 18449932
    微博: officecn01
    移動(dòng)訪問(wèn)