Reload query in form

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
 
G

Guest

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
 
G

Guest

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Requery problem 2
Reset form recordsource 4
Query from a Form 1
Multi-Select List Box 2
Opening Query from Form 4
Passing Parameter From Form mismatched criteria 10
#Name? 1
Err Msg Prob 1

Top