RecordsetClone SQL string

  • Thread starter Thread starter DataCorp
  • Start date Start date
D

DataCorp

I am trying to retrieve the RecordsetClone SQL string form a filtered form.

I just can't get a handle on how to do this.

Thanks
 
I am trying to retrieve the RecordsetClone SQL string form a
filtered form.

I just can't get a handle on how to do this.

Thanks
That's because there is no handle.
use the form's recordsource property to determine the name of the
query, then go through the querydefs collection to retrieve the SQL.
If it's not found, it will be either a table name or the SQL. If it
starts with "SELECT " then you have the SQL, if it's a table name,
then the SQL will be "SELECT * From " & the table name.Get the
filter conditions from the form's FilterBy property. and the " WHERE
" and the contents of the FilterBy property.

Having explained that, I ask what are you trying to get this,
because there always is a better way.
 
The MyForm form is in filter by form mode with filters applied.



I might be wrong but I believe the filter is applied to the RecordsetClone
and not the underlying query.



MyForm is opened from Form1. Form 1 uses a query as its recordsource. When I
close MyForm with its filters applied, I want to see the same records in
form 1 as I had in MyForm.



I can save the filtered records as a query and get the information I need
that way but would rather look at the RecordsetClone filter SQL before the
form closes, extract the filter text from it and apply it to Form1.



I cannot use the same recordsource for both forms.



I hope this makes sense.
 
The MyForm form is in filter by form mode with filters applied.

I might be wrong but I believe the filter is applied to the
RecordsetClone and not the underlying query.
It might be, but it is not accessible.
MyForm is opened from Form1. Form 1 uses a query as its
recordsource. When I close MyForm with its filters applied, I want
to see the same records in form 1 as I had in MyForm.
The Filter property IS populated by the Filter by Form tool.

So if you have a close button on MyForm, just set one line of code
to make Forms!Form1.Filter = Me.Filter and anothre to turn the
filter on Forms!Form1.FilterOn = true
I can save the filtered records as a query and get the information
I need that way but would rather look at the RecordsetClone filter
SQL before the form closes, extract the filter text from it and
apply it to Form1.

I cannot use the same recordsource for both forms.

Hopefully your forms will have matching field names,
I hope this makes sense.
Having seen and understood what you want to do, my proposal is a lot
simpler. Try it.
Bob Quintal said:
That's because there is no handle.
use the form's recordsource property to determine the name of the
query, then go through the querydefs collection to retrieve the
SQL. If it's not found, it will be either a table name or the
SQL. If it starts with "SELECT " then you have the SQL, if it's a
table name, then the SQL will be "SELECT * From " & the table
name.Get the filter conditions from the form's FilterBy property.
and the " WHERE " and the contents of the FilterBy property.

Having explained that, I ask what are you trying to get this,
because there always is a better way.
 
Thanks for the help :)

Bob Quintal said:
The MyForm form is in filter by form mode with filters applied.

I might be wrong but I believe the filter is applied to the
RecordsetClone and not the underlying query.
It might be, but it is not accessible.
MyForm is opened from Form1. Form 1 uses a query as its
recordsource. When I close MyForm with its filters applied, I want
to see the same records in form 1 as I had in MyForm.
The Filter property IS populated by the Filter by Form tool.

So if you have a close button on MyForm, just set one line of code
to make Forms!Form1.Filter = Me.Filter and anothre to turn the
filter on Forms!Form1.FilterOn = true
I can save the filtered records as a query and get the information
I need that way but would rather look at the RecordsetClone filter
SQL before the form closes, extract the filter text from it and
apply it to Form1.

I cannot use the same recordsource for both forms.

Hopefully your forms will have matching field names,
I hope this makes sense.
Having seen and understood what you want to do, my proposal is a lot
simpler. Try it.
 
Back
Top