Reset form recordsource

B

Beetle

A bit of background to start.

A2003, split, multi-user. I have a form that uses a stored query as it's
recordsource. The query (qryDeliveries) pulls a limited number of records
from the table (the previous 7 days worth). In the header of the form are
unbound controls that are used for searching. When the users do a search
they need to be able to search the entire table, so in the click event of
the Search command button, I change the form's recordsource to a
SQL statement that is built from what they select in the unbound controls.

That part works perfectly. The part that seems like it should be the easiest
is giving me headaches. I have a Reset command buuton on the form
where I am attempting to change the form's recorsource back to the
original stored query. I can't seem to get Access to recognize the stored
query. I get a message that says "The recordsource you specified for this
form doesn't exist". I believe I need to use QueryDefs for this, but I must be
missing something. What I am currently attempting is;

Dim qdf As QueryDef
Set qdf = Currentdb.QueryDefs ("qryDeliveries")

Me.Recordsource = "qdf"

qdf.Close
Set qdf = Nothing

I've tried a few minor variations of the above with no luck. Maybe I'm wrong
about using QueryDefs for this in the first place. Just for grins I tried
setting
the recordsource to the query name directly, even though I didn't think it
would work, which it didn't. I'm a little stumped (nothing new <g>). Feel
free to point out if I'm just being an idiot :)
 
M

Mr B

Beetle,

All you should need to do is to specify the record source and then requey
the control, like:

Me.recordsource = "qryDeliveries"
Me.requery
 
B

Beetle

Funny. I swear I had already tried that and it didn't work at the time, but
it does now. Apparently, I had my head inserted in an inappropriate place
at the time. I know the recordsource property is a string, so I'm pretty sure
I didn't forget the quotes, but maybe. Anyway, thanks Mr B.
 
M

Marshall Barton

Mr B said:
All you should need to do is to specify the record source and then requey
the control, like:

Me.recordsource = "qryDeliveries"
Me.requery


Setting the Record Source automatically loads the new
dataset. so the Requery is a waste of time and resources.
 
M

Mr B

Glad you were able to make it work.

As Marshal has indicated, you should not need the requery. Try removing
that and test it again.

I included that because I wanted to make absolutely sure that you got the
data loaded.
 

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

Top