|
本帖最后由 yuzhusisi 于 2013-1-10 11:22 编辑
我有一个工资表,想把每个人的数据导出成一个txt文件,以人名为文件名,现在导出的功能实现了,但是导出后只是字段值,想把字段名加进去后一起导出,怎么实现呀?
如现在导出的结果是:李小明,500
我想变成:
姓名:李小虎 ,基本工资:500
原文件的代码
Private Sub 导出数据_Click()
Dim rs As Object
Dim rst As Object
Dim strT As String
Dim strFileName As String
Dim lngHandle As Long
Set rs = CreateObject("adodb.recordset")
rs.ActiveConnection = CurrentProject.Connection
rs.Open ("select distinct 姓名 from 工资表")
Set rst = CreateObject("adodb.recordset")
rst.ActiveConnection = CurrentProject.Connection
Do Until rs.EOF
rst.Open ("select [姓名],[基本工资] from 工资表 where 姓名='" & rs(0) & "'")
strT = rst.GetString(, , ",", Chr(13) & Chr(10))
rst.Close
strFileName = CurrentProject.Path & "\" & "数据" & "\" & rs(0) & ".txt"
lngHandle = FreeFile()
Open strFileName For Output As lngHandle
Print #lngHandle, strT
Close lngHandle
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set rst = Nothing
MsgBox "数据导出完成! "
End Sub |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|