Private Sub Command0_Click()
Dim RR As Recordset
Set RR = CurrentDb.OpenRecordset("SELECT CID & ',' & 12 FROM B1")
Open "D:\报表系统\1.TXT" For Output As #2
Do While Not RR.EOF
Print #2, RR(0)
RR.MoveNext
Loop
Close #2
End Sub
这是一个把ACCESS表导成文本文件的代码,此代码只能导出ACCESS的数据,我需要导出的文本文件第一行为ACCESS表的字段名,请问需要怎么修改,还请高手指点!作者: todaynew 时间: 2009-9-28 17:53
试试:
RR(0).name作者: bjyutong 时间: 2009-9-28 17:56
不行,RR(0)改成RR(0).NAME之后,引出的数据就全是"Expr1000"这个了作者: aslxt 时间: 2009-9-28 18:47
参考:
Private Sub Command0_Click()
Dim str
Dim sstr
Dim RR As Recordset
Set RR = CurrentDb.OpenRecordset("SELECT * FROM 表1")
Open "g:\111.TXT" For Output As #2
For i = 1 To RR.Fields.Count
str = str & " " & RR.Fields(i - 1).Name
Next i
Print #2, Trim(str)
Do While Not RR.EOF
For i = 1 To RR.Fields.Count
sstr = sstr & " " & RR.Fields(i - 1)
Next i
Print #2, Trim(sstr)
sstr = ""
RR.MoveNext
Loop
Close #2
End Sub作者: bjyutong 时间: 2009-9-29 13:01 4#aslxt
Set RR = CurrentDb.OpenRecordset("SELECT * FROM 凭证转换器02查询")
我把这些代码考到我做的程序里,这句报错类型不匹配,但是我把'凭证转换器02查询'表考到一个单独的ACCESS表里,就不报错,我不知道是怎么回事,还望您能帮忙想想是怎么回事!谢谢!!作者: wfkbabro 时间: 2009-9-29 16:19
Set RR = CurrentDb.OpenRecordset("SELECT CID & ',' & 12 FROM B1")
改变为
Set RR = CurrentDb.OpenRecordset("SELECT CID & ',' & 12 as CId_12 FROM B1")
要回复哦作者: wfkbabro 时间: 2009-9-29 16:21
希望用as 后 RR(0).NAME 不是 Expr1000了作者: tmtony 时间: 2009-9-30 12:15
在导入数据之前,先插入字段名称到文本文件中
for each fld in RR.fields
Print #2, fld.name
next