标题: 追加交叉表查询数据到一个完整的表里 [打印本页] 作者: Victor_Duane 时间: 2007-8-19 17:57 标题: 追加交叉表查询数据到一个完整的表里 有时候做交叉表的时候知道表中有多少的字段,要计算字段与字段之间运算关系的时候,因为交叉表列数是不稳定的,所以我把得到的数据追加到一个固定的表\的字段中然后计算字段之间的关系,这个函数也适合用于追加表标题相同的数据到另一个表中
'参数1:strFromTable 为用交叉表得到数据的查询名称,strInto为你要添加数据的表
Public Function varInsertTable(strFromTable As String, strIntoTable As String)
''追加数据到一个完整的表里
Dim rst As DAO.Recordset
Dim fld As Field
Dim fldName As String
Set rst = CurrentDb.OpenRecordset(strFromTable, dbOpenDynaset)
For Each fld In rst.Fields
fldName = fldName & fld.Name & ","
Next
fldName = Left(fldName, Len(fldName) - 1)
''Debug.Print fldName
strSQL = "INSERT INTO " & strIntoTable & "(" & fldName & " ) SELECT " & fldName & " FROM " & strFromTable & ";"
''Debug.Print strSQL
DoCmd.RunSQL strSQL
End Function
'参数1:strFromTable 为用交叉表得到数据的查询名称,strInto为你要添加数据的表
Public Function varInsertTable(strFromTable As String, strIntoTable As String)
''追加数据到一个完整的表里
Dim rst As DAO.Recordset
Dim fld As Field
Dim fldName, strsql As String
Dim i_fld As Integer
Set rst = CurrentDb.OpenRecordset(strFromTable, dbOpenDynaset)
'For Each fld In rst.Fields
For i_fld = 0 To rst.Fields.Count - 1
'fldName = rst.Fields(i_fld).Name
fldName = fldName & rst.Fields(i_fld).Name & ","
Next
fldName = Left(fldName, Len(fldName) - 1)
''Debug.Print fldName
strsql = "INSERT INTO " & strIntoTable & "(" & fldName & " ) SELECT " & fldName & " FROM " & strFromTable & ";"
''Debug.Print strSQL
DoCmd.RunSQL strsql
End Function作者: xie62 时间: 2010-9-8 10:53