|
多谢大家的支持。我已经搞定了。
Sub union()
Dim str As String
Dim end_day As Date
end_day = #4/20/2008#
For i = end_day To end_day - 10 Step -1
If fExistTable("plmn_kpi" & Format(i, "yyyymmdd")) Then
str = "select * from plmn_kpi" & Format(i, "yyyymmdd")
Exit For
End If
Next
For i = end_day To end_day - 10 Step -1
If fExistTable("plmn_kpi" & Format(i, "yyyymmdd")) Then
str = str & " union select * from plmn_kpi" & Format(i, "yyyymmdd")
End If
Next
DoCmd.RunSQL ("select * into plmn_kpi from (" & str & ")")
End Sub
Function fExistTable(strTableName As String) As Integer
Dim db As Database
Dim i As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
fExistTable = False
db.TableDefs.Refresh
For i = 0 To db.TableDefs.Count - 1
If strTableName = db.TableDefs(i).Name Then
'Table Exists
fExistTable = True
Exit For
End If
Next i
Set db = Nothing
End Function |
|