Reload query in form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query for my recordsource then on my form I have the user select
different filter options. I modify the query using

Dim dbs As Database
Dim qdf As QueryDef
Set dbs as CurrentDb
Set qdf = dbs.QueryDefs("Query1")

<Bunch of Filtering Code in Here>

qdf.SQL = "Insert New SQL Statement Here"
Me.Requery
Me.Requery

qdf.Close

When I change the SQL statement, the statements themselves work but I need
to close the form and open it again in order for the filter to work. I've
tried using Me.Refresh and I've tried putting the Me.Requery after the
qdf.Close. It didn't work.

I've tried altering the Recordsource before using Me.Recordsource = "Insert
New SQL Statement Here" and it works great. I can't use it this time because
the SQL statement is too long.

How can I reload the query in the form without closing the form?

Thanks,
Can

reload query in form
 
Since you have changed the qdf of Query1, I would think you can just change
the recordsource of the form to Query1.

Me.Recordsource = "Query1"

....rather than the SQL itself...

Steve
 
It works. After I altered the SQL statement I just reset the recordset to
Me.Recordsource = "Query1"
Then did a Me. Requery
 
Back
Top