Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

请帮忙看一下我的代码为什么不能从TXT文件插入到表中?

李志能  发表于:2014-05-25 14:27:21  
复制

                Open "D:\111.txt" For Input As #1


                For i = 0 To 11
                    Input #1, ddd(i)
                    Debug.Print ddd(i) '这里显示的结果是正确的
                Next
                CurrentDb.Execute "INSERT INTO tblZhiJu Engineering, WorkDate,CeLiangYuan1,CeLiangYuan2,JiLuYuan,ZuoTuYuan,XA,[yA],[zA],[Xb],[yb],[zb] " & _
                                  "VALUES (ddd(0),ddd(1),ddd(2),ddd(3),ddd(4),ddd(5),ddd(6),ddd(7),ddd(8),ddd(9),ddd(10),ddd(11))"


                Do Until EOF(1)
                    For i = 0 To 5
                        Input #1, ddd(i)
                        Debug.Print ddd(i) '这里显示的结果是正确的
                    Next
                    CurrentDb.Execute "INSERT INTO tblZhiJuDetailed ZhiJuID, ZhuChi,BiaoJi,ChiZuo,ChiYou,ChiShang,ChiXia " & _
                                      "VALUES (ddd(0),ddd(1),ddd(2),ddd(3),ddd(4),ddd(5))"
                Loop

 

Top
杜超-2号 发表于:2014-05-26 08:38:48
【Access源码示例】-导入导出系列-根据SQL语句导出数据到txt记事本[Access软件网]
http://www.accessoft.com/article-show.asp?id=7360

善解人衣 发表于:2014-05-28 15:18:18
Private Sub cmdDRYSJL_Click()
    Dim strSourceFile As String
    Dim strPath, strpath1 As String
    Dim strLine As String
    Dim intBkp, intID As Integer
    Dim intYear, intMonth As Integer
    Dim strSQL As String
    Dim cnn As Object           'ADODB.Connection
    Dim rst As Object           'ADODB.Recordset
    Dim i, j As Integer
    Dim ddd(11) As Variant

    strPath = "\\Mlks23\技术股\支距测量记录\DAT"
    On Error Resume Next
    '    MkDir strdir '创建文件夹
    ' 现在查找存在的TXT文件
    For intYear = 1900 To Year(Now())
        For intMonth = 1 To 12
            strpath1 = strPath & "\" & intYear & "-" & Format(intMonth, "00")
            '                MsgBox strPath
            Debug.Print strpath1
            strSourceFile = Dir(strpath1 & "\*.txt")
            Do While Len(strSourceFile) > 0
                intBkp = intBkp + 1
                Debug.Print strpath1 & "\" & strSourceFile

                Open strpath1 & "\" & strSourceFile For Input As #1

                For i = 0 To 11
                    Input #1, ddd(i)
                    Debug.Print ddd(i)
                Next
                Set cnn = CurrentProject.Connection

                strSQL = "SELECT * FROM [tblZhiJu]"
                Set rst = OpenADORecordset(strSQL, adLockOptimistic, cnn)
                rst.AddNew
                rst![Engineering] = CStr(ddd(0))
                rst![WorkDate] = CDate(ddd(1))
                rst![CeLiangYuan1] = CStr(ddd(2))
                rst![CeLiangYuan2] = CStr(ddd(3))
                rst![JiLuYuan] = CStr(ddd(4))
                rst![ZuoTuYuan] = CStr(ddd(5))
                rst![XA] = CSng(ddd(6))
                rst![YA] = CSng(ddd(7))
                rst![ZA] = CSng(ddd(8))
                rst![XB] = CSng(ddd(9))
                rst![YB] = CSng(ddd(10))
                rst![ZB] = CSng(ddd(11))
                rst.Update
                intID = rst![ZhiJuID]
                rst.Close
                
                Do Until EOF(1)
                    For i = 0 To 5
                        Input #1, ddd(i)
                        Debug.Print ddd(i)
                    Next
                    strSQL = "SELECT * FROM [tblZhiJuDetailed]"
                    Set rst = OpenADORecordset(strSQL, adLockOptimistic, cnn)
                    rst.AddNew
                    rst![ZhiJuID] = intID
                    rst![ZhuChi] = CSng(ddd(0))
                    rst![BiaoJi] = CStr(ddd(1))
                    rst![ChiZuo] = CSng(ddd(2))
                    rst![ChiYou] = CSng(ddd(3))
                    rst![ChiShang] = CSng(ddd(4))
                    rst![ChiXia] = CSng(ddd(5))
                    rst.Update
                    rst.Close
                Loop
                Close #1
                ' 获取下一个文件
                strSourceFile = Dir
            Loop
        Next
    Next
    MsgBox "共导入完成 " & intBkp & " 个文件!"
End Sub


搞定了!900多个文件,5分钟才导入完成!


总记录:2篇  页次:1/1 9 1 :