Query will not update table in subform MS-Access

2019-03-05 02:25发布

问题:

I created a table in MS-Access 2010 by running the following script on SQL server 2008

SELECT * into qryInstrumentInterfacelog FROM tblInstrumentInterfaceLog

qryInstrumentInterface is used to populate a subform on the main form. After a "Process" button is pressed, files are read in and stored in the database. tblInstrumentInterface will be inserted with a new record everytime a new file is read in. My problem is qryInstrumentInterfacelog will not update with tblInstrumentInterfaceLog, it will just keep the same data it had when the script was first ran on the server. I have tried different methods to requery the subform but I realized the subform had no issues it was the actual table that wasn't changing. How can I get qryInstrumentInterfacelog to be dynamic and update as tblInstrumentInterfaceLog updates? Is my SQL code wrong?

回答1:

Well, one important concern is that, indeed, you cannot repeat the query as written.

"Select... into" creates a new table only. It does not insert/append to such a table.
So if you are really calling that a second time, it is probably erroring out.

If you really want to drop and replace the table, make sure to call an explicit "Drop Table" in advance of your "Select...Into".

--
A typical pattern, in SQL Server t-sql, is

if object_id('*your_table_name*') is not null  
  drop table *your_table_name*
;  
*...your select...into*