1

at the first, I should explain my scenario to declare what I will do:

I want to merge records in one Table and then save them in another table. Why? I had a very complex query which needs long time to run and give back the result. I decided to divide this query into two query and save the resulat of the first query into a table and then the second query use the new generated table the source table is often updated and the generated table must be generated too If I use this code on my VBA this error occured: Error 3010 Table already exist

Set db = CurrentDb
  ssql = "SELECT DISTINCT tb_KonzeptDaten.DFCC,  " _
  & "tb_KonzeptDaten.OBD_Code AS Konzept_Obd,tb_KonzeptDaten.DFC " _
  & "INTO Test_Table FROM tb_KonzeptDaten"
  db.Execute ssql, dbFailOnError
  RecordsUpdated = db.RecordsAffected

have you any idea ? do we have another SQL statement to do this job?

4

1 に答える 1

1

テーブルが既に存在する場合は、VBA でテーブルを削除してから、クエリを実行できます。

tblName = "TableX"
tbl = DLookup("Name", "MSysobjects", "Type=1 and Name='" & tblName & "'")

If Not IsNull(tbl) Then
    DoCmd.DeleteObject acTable, tbl
End If

または

Set db = CurrentDb
ssql = "DELETE FROM Test_Table"
db.Execute ssql, dbFailOnError

ssql = "INSERT INTO Test_Table SELECT DISTINCT tb_KonzeptDaten.DFCC,  " _
  & "tb_KonzeptDaten.OBD_Code AS Konzept_Obd,tb_KonzeptDaten.DFC " _
  & "FROM tb_KonzeptDaten"
db.Execute ssql, dbFailOnError
于 2012-09-04T10:05:48.683 に答える