Requery problem

  • Thread starter Thread starter Beetle
  • Start date Start date
B

Beetle

I'm sure I'm missing something simple here, but I'm just not seeing it
right now.

A2003. I have a form which uses a query as it's recordset. I have a command
button on the form that resorts the records when clicked. The code all works
fine except that the form won't requery. The stored query gets the new SQL
an if I open it directly it shows the correct results, but the form won't
show the
new query records until I close and reopen it, even with Me.Requery in the
code.
Code (example) is as follows;

Dim strSQL As String
Dim qdf As QueryDef

strSQL = "blah blah blah a bunch of SQL"

set qdf = Currentdb.QueryDefs ("qryCustomerSort")

qdf.SQL = strSQL
Me.Requery '<<< this doesn't work

qdf.Close
Set qdf = Nothing

Like I said, I'm probably missing something completely obvious, but so far
all I'm getting is bruises on my forehead.

Any ideas?
 
If me.requery doesn't work why not reset the recordsource to see if that helps.

I assume the querydef is the recordsource for the form.
After you've created the querydef set the recordsource to "" and then
re-attach the recordsource by setting it to the querydef.

me.recordsource="qryCustomerSort"
and the me.requery for a final tick
 
Yeah, that worked. I just had to do;

qdf.SQL = strSQL
Me.RecordSource = "qryCustomerSort"

No need to set the RecordSource to "" or to requery.

Thanks for the jump.
 
Back
Top