Use Select query as LinkCriteria with OpenForm method?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to reference a select query to provide criteria for the Open
Form method.
Example : str1 = "[PlantID] = qselFilterPests.PlantID"
strLinkCriteria = strLinkCriteria & str1
DoCmd.OpenForm strDocName, , , strLinkCriteria

The first '[PlantID]' above is one of the bound fields on my form.
'strDocName' refers to the form.
The problem is that when Access runs, it treats the part
'qselFilterPests.PlantID' as if it is a parameter query rather than an
already created and saved select query.
Do I need to have some sort of object reference before
qselFilterPests.PlantID as you would use when referencing a form such as
Forms![formname]![fieldname].

I seem to have a lot of problems with finding the correct syntax to use at
times even after going through Access help files so any help would be much
appreciated.
 
Why don't you do the filtering as part of the form's query?
Just link your current datasource to qselFilterPests and only matching
records will be returned.

Regards,
Andreas
 
Thanks Andreas, I thought that by including my query as part of the string
for the link criteria that this would link my filter/query. The filter is
only applied if the user checks a check box on the form. The form already is
linked to a query so if the check box is selected this query then has the
filter/query applied to it. If I link the forms datasource to
qselFilterPests the other fields on the form will not have anything to link
to as they will have lost their datasource. qselFilterPests only filters one
field on the form.

Andreas said:
Why don't you do the filtering as part of the form's query?
Just link your current datasource to qselFilterPests and only matching
records will be returned.

Regards,
Andreas
Is it possible to reference a select query to provide criteria for the Open
Form method.
Example : str1 = "[PlantID] = qselFilterPests.PlantID"
strLinkCriteria = strLinkCriteria & str1
DoCmd.OpenForm strDocName, , , strLinkCriteria

The first '[PlantID]' above is one of the bound fields on my form.
'strDocName' refers to the form.
The problem is that when Access runs, it treats the part
'qselFilterPests.PlantID' as if it is a parameter query rather than an
already created and saved select query.
Do I need to have some sort of object reference before
qselFilterPests.PlantID as you would use when referencing a form such as
Forms![formname]![fieldname].

I seem to have a lot of problems with finding the correct syntax to use at
times even after going through Access help files so any help would be much
appreciated.
 
Sorry but could anybody please answer my original qusetion about if it is
possible to use the method I gave in my example.
 
Still not 100% clear on what you are after.
Here are my presumptions:
- You have a form (frm1)with a checkbox on it
- The user clicks a button which opens another form (frm1)
- If the ticked the checkbox on frm1, then apply a filter to frm2 when
it opens, otherwise don't.

Is this correct?

Regards,
Andreas

Thanks Andreas, I thought that by including my query as part of the string
for the link criteria that this would link my filter/query. The filter is
only applied if the user checks a check box on the form. The form already is
linked to a query so if the check box is selected this query then has the
filter/query applied to it. If I link the forms datasource to
qselFilterPests the other fields on the form will not have anything to link
to as they will have lost their datasource. qselFilterPests only filters one
field on the form.

:

Why don't you do the filtering as part of the form's query?
Just link your current datasource to qselFilterPests and only matching
records will be returned.

Regards,
Andreas
Is it possible to reference a select query to provide criteria for the Open
Form method.
Example : str1 = "[PlantID] = qselFilterPests.PlantID"
strLinkCriteria = strLinkCriteria & str1
DoCmd.OpenForm strDocName, , , strLinkCriteria

The first '[PlantID]' above is one of the bound fields on my form.
'strDocName' refers to the form.
The problem is that when Access runs, it treats the part
'qselFilterPests.PlantID' as if it is a parameter query rather than an
already created and saved select query.
Do I need to have some sort of object reference before
qselFilterPests.PlantID as you would use when referencing a form such as
Forms![formname]![fieldname].

I seem to have a lot of problems with finding the correct syntax to use at
times even after going through Access help files so any help would be much
appreciated.
 
Andreas I did try what you suggested and it worked so cheeers for your help.

Andreas said:
Still not 100% clear on what you are after.
Here are my presumptions:
- You have a form (frm1)with a checkbox on it
- The user clicks a button which opens another form (frm1)
- If the ticked the checkbox on frm1, then apply a filter to frm2 when
it opens, otherwise don't.

Is this correct?

Regards,
Andreas

Thanks Andreas, I thought that by including my query as part of the string
for the link criteria that this would link my filter/query. The filter is
only applied if the user checks a check box on the form. The form already is
linked to a query so if the check box is selected this query then has the
filter/query applied to it. If I link the forms datasource to
qselFilterPests the other fields on the form will not have anything to link
to as they will have lost their datasource. qselFilterPests only filters one
field on the form.

:

Why don't you do the filtering as part of the form's query?
Just link your current datasource to qselFilterPests and only matching
records will be returned.

Regards,
Andreas

AdeyS wrote:

Is it possible to reference a select query to provide criteria for the Open
Form method.
Example : str1 = "[PlantID] = qselFilterPests.PlantID"
strLinkCriteria = strLinkCriteria & str1
DoCmd.OpenForm strDocName, , , strLinkCriteria

The first '[PlantID]' above is one of the bound fields on my form.
'strDocName' refers to the form.
The problem is that when Access runs, it treats the part
'qselFilterPests.PlantID' as if it is a parameter query rather than an
already created and saved select query.
Do I need to have some sort of object reference before
qselFilterPests.PlantID as you would use when referencing a form such as
Forms![formname]![fieldname].

I seem to have a lot of problems with finding the correct syntax to use at
times even after going through Access help files so any help would be much
appreciated.
 

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

Back
Top