Weird Bug: “DoCmd.OutputTo acOutputQuery” is delet

2019-04-13 01:00发布

问题:

I'm encountering a problem where DoCmd.OutputTo acOutputQuery deletes the query itself the second time it is run.

Is there any workaround/patch for this bug (at least seems like a bug to me)?

回答1:

Re: your comment.

Did you do a file copy, or did you copy the objects between two databases? IF the second, you might want to try doing a compact and repair on a file-copy of the original.

You might even want to try that on the real original.



回答2:

I think the behaviour you described "...deletes the query itself, the second time it is run" occurs when the query returns no records.



回答3:

even 2007 has this problem, it is happening to me also, but very randomly. Sometimes I can run it many times before the bug happens, other times it happens right away, it's a small database, 29 records, and a tiny query, so it's definitely a bug in access



回答4:

I know it's been awhile since the original post, but I have found a solution that I did not see here. I'm using Access 2010. It seems that almost everytime I execute DoCmd.OutputTo acOutputQuery..., my saved query still appears in my list of queries, but the SQL gets wiped out, which subsequently deletes my output file too from the network.

I just reset the SQL before calling DoCmd.OutputTo acOutputQuery...

CurrentDb.QueryDefs("MyQuery").SQL = "SELECT..."

and then call

DoCmd.OutputTo acOutputQuery, "MyQuery"...

So far so good.



回答5:

it happens to me too. I'm using Access 2003.

The only workaround I've found is to preserve a copy of the original mdb, this way I can restore the mdb when it happens.

It seems that Access 2007 doesn't have this problem.



回答6:

Another workaround is to change the original query to a make table query, and then use

DoCmd.OutputTo acOutputTable, TableName, ...

It means you have an extra table hanging around, but you could always do a delete table in code or via a query afterwards to clean up.