J
James Schoemaker
If anyone can tell me what is incorrect or what I should be doing, it
would be most appreciated.
Here is what I am trying to do:
1. Create an Indexed Table of Unique ID Numbers.
2. Load the table with data from four separate Queries,
based upon specific criteria, filtering out duplicate
ID Numbers.
The code works fine up to the point where the records are inserted into
the newly created table. The four queries work fine if run by
themselves. But, it fails with a "Invalid Syntax" error on the SQL
statement. Here is the code:
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim idx As ADOX.index
Dim col As ADOX.Column
Dim rst As ADODB.Recordset
' delete the old table and create a new one
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
cat.ActiveConnection = CurrentProject.Connection
On Error Resume Next
cat.Tables.Delete "tbl_PersonID"
tbl.Name = "tbl_PersonID"
tbl.Columns.Append "IDno", adInteger
cat.Tables.Append tbl
cat.Tables.Refresh
' build an index without duplicates
Set idx = New ADOX.index
Set col = New ADOX.Column
col.Name = "IDno"
idx.Name = "IDno"
idx.PrimaryKey = False
idx.Unique = True
idx.Columns.Append col
tbl.Indexes.Append idx
Set cat = Nothing
Set tbl = Nothing
Set idx = Nothing
Set col = Nothing
' append in any of the selected records
Set rst1 = New ADODB.Recordset
rst1.Open "INSERT INTO tbl_PersonID " & _
"TABLE qry_Records_1 " & _
"UNION " & _
"TABLE qry_Records_2 " & _
"UNION " & _
"TABLE qry_Records_3 " & _
"UNION " & _
"TABLE qry_Records_4", _
CurrentProject.Connection, adOpenDynamic, _
adLockOptimistic, adCmdText
rst1.Close
Set rst1 = Nothing
I hope someone can spot what is wrong, or what I should be doing
instead. Thanks....
would be most appreciated.
Here is what I am trying to do:
1. Create an Indexed Table of Unique ID Numbers.
2. Load the table with data from four separate Queries,
based upon specific criteria, filtering out duplicate
ID Numbers.
The code works fine up to the point where the records are inserted into
the newly created table. The four queries work fine if run by
themselves. But, it fails with a "Invalid Syntax" error on the SQL
statement. Here is the code:
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim idx As ADOX.index
Dim col As ADOX.Column
Dim rst As ADODB.Recordset
' delete the old table and create a new one
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
cat.ActiveConnection = CurrentProject.Connection
On Error Resume Next
cat.Tables.Delete "tbl_PersonID"
tbl.Name = "tbl_PersonID"
tbl.Columns.Append "IDno", adInteger
cat.Tables.Append tbl
cat.Tables.Refresh
' build an index without duplicates
Set idx = New ADOX.index
Set col = New ADOX.Column
col.Name = "IDno"
idx.Name = "IDno"
idx.PrimaryKey = False
idx.Unique = True
idx.Columns.Append col
tbl.Indexes.Append idx
Set cat = Nothing
Set tbl = Nothing
Set idx = Nothing
Set col = Nothing
' append in any of the selected records
Set rst1 = New ADODB.Recordset
rst1.Open "INSERT INTO tbl_PersonID " & _
"TABLE qry_Records_1 " & _
"UNION " & _
"TABLE qry_Records_2 " & _
"UNION " & _
"TABLE qry_Records_3 " & _
"UNION " & _
"TABLE qry_Records_4", _
CurrentProject.Connection, adOpenDynamic, _
adLockOptimistic, adCmdText
rst1.Close
Set rst1 = Nothing
I hope someone can spot what is wrong, or what I should be doing
instead. Thanks....