Thanks for your reply. But it's still not working. As I said, the SQL statement runs well by itself. It just doens't work when I put it at the end of other VBA codes. I can make a query by the sql statement given before. The query runs OK by itself, but it doesn't work when I use DoCmd Openquery...