用vb命令将access的数据表信息导出txt文件
请问,在VB中,通过什么方法将ACCESS中的某个表导出为txt文本文件?是通过VB编程,书写VB命令,操作数据库,导出TXT。最好有集体的代码过程(比如说要创建模块之类...
请问,在VB中,通过什么方法将ACCESS中的某个表导出为txt文本文件?
是通过VB编程,书写VB命令,操作数据库,导出TXT。
最好有集体的代码 过程(比如说要创建模块之类的 ) 展开
是通过VB编程,书写VB命令,操作数据库,导出TXT。
最好有集体的代码 过程(比如说要创建模块之类的 ) 展开
展开全部
Public conn As ADODB.Connection 'conn为连接
Public rs As New ADODB.Recordset 'rs为记录集
Public sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path_sjk & ";Jet OLEDB:Database Password=123" '打开数据源
sql = "SELECT 名称,规格,SUM(数量) & 单位 AS 汇总, COUNT(名称) as 记录数 FROM 材料 GROUP BY 名称,规格,单位"
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
Open App.Path & "\dat\dc.txt" For Output As #1
For j = 0 To rs.Fields.Count - 1
Print #1, rs.Fields(j).Name; Space(16);
Next j
Print #1,
For i = 0 To rs.RecordCount - 1
For j = 0 To rs.Fields.Count - 1
s = Trim(rs.Fields(j) & "")
If s = "" Then
Print #1, s; Space(20);
Else
Print #1, s; Space(20 - LenB(StrConv(s, vbFromUnicode)));
End If
Next j
Print #1,
rs.MoveNext
Next i
Close #1
MsgBox "导出完成"
rs.MoveFirst
Shell "c:\windows\Notepad.exe " + App.Path + "\dat\dc.txt", vbNormalFocus
Public rs As New ADODB.Recordset 'rs为记录集
Public sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path_sjk & ";Jet OLEDB:Database Password=123" '打开数据源
sql = "SELECT 名称,规格,SUM(数量) & 单位 AS 汇总, COUNT(名称) as 记录数 FROM 材料 GROUP BY 名称,规格,单位"
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
Open App.Path & "\dat\dc.txt" For Output As #1
For j = 0 To rs.Fields.Count - 1
Print #1, rs.Fields(j).Name; Space(16);
Next j
Print #1,
For i = 0 To rs.RecordCount - 1
For j = 0 To rs.Fields.Count - 1
s = Trim(rs.Fields(j) & "")
If s = "" Then
Print #1, s; Space(20);
Else
Print #1, s; Space(20 - LenB(StrConv(s, vbFromUnicode)));
End If
Next j
Print #1,
rs.MoveNext
Next i
Close #1
MsgBox "导出完成"
rs.MoveFirst
Shell "c:\windows\Notepad.exe " + App.Path + "\dat\dc.txt", vbNormalFocus
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询