Adding criteria to an existing query without saving the query, VBA (1 Viewer)

Hello1

Registered User.
Local time
Today, 17:31
Joined
May 17, 2015
Messages
271
Is there way to add a temporary criteria to a queries field, that query is used for a reports record source.
I do have a code which changes one of the queries criteria into another, using .Parameters, something like this.

Code:
Set MyQry = MyDb.QueryDefs("qryQuery1")
MyQry.Parameters("forms!frmFormName!cboControl") = [Forms]![frmFormName1111]![cboControl]

But how could I add a temporary criteria to a field which doesnt have a criteria?
It might me a silly question, but forgive me, Im still learning :eek:
Thanks
 
Last edited:

June7

AWF VIP
Local time
Today, 06:31
Joined
Mar 9, 2014
Messages
5,470
Is the name of cboContorl misspelled?

Can't. The query would have to be modified, either manually or with VBA.

I don't use dynamic parameterized queries. I build criteria with VBA and apply to form or report when opening with DoCmd.OpenForm (or OpenReport). Review http://allenbrowne.com/ser-62.html
 

Hello1

Registered User.
Local time
Today, 17:31
Joined
May 17, 2015
Messages
271
Yes was a typo, thanks.
Alright, I checked the link and created a variable which contains the WHERE condition and added it to the report open filter code.
It works as I wanted it to, nice :)
Are there any downsides to this?
Thanks!
 

June7

AWF VIP
Local time
Today, 06:31
Joined
Mar 9, 2014
Messages
5,470
Won't be helpful if you want to export queries directly, say to Excel.

Also, if need to filter subreports beyond what is done by the Master/Child Links, won't work.
 

Hello1

Registered User.
Local time
Today, 17:31
Joined
May 17, 2015
Messages
271
I do need to export the same report to PDF at another button click but with different filter this time.
Code:
DoCmd.OutputTo acOutputReport
As I see here I cant put a filter? :(
So seems I will have to go for another solution.
 

June7

AWF VIP
Local time
Today, 06:31
Joined
Mar 9, 2014
Messages
5,470
Can export report. It's a query won't work for.

Open the report to PrintPreview then run the OutputTo.
 

Users who are viewing this thread

Top Bottom