If you are using VB 6.0 then the answer is in the post 2, and for VB.NET you can pass the SQL query according to the condition.