Query parameter only when opening in form (1 Viewer)

MattCSI

New member
Local time
Yesterday, 23:32
Joined
Jan 10, 2019
Messages
2
Query asks for parameter, but only when opening in form

Hello,
I have a query which reads from multiple tables and uses criteria to filter on a yes/no field. It works correctly when viewing in Datasheet view, but does not work when passed in VBA code to open a form.

I believe the field names are spelled correctly, because I used the Query Design to add the field names, and as I noted, it works in Datasheet view.

When using VBA to open the form, a box pops up asking for a parameter for the Yes/No field. Regardless of what is input in the box, the form doesn't filter the view by this field.

I should note, this was working correctly until recently when I started to tinker with it. I wish I could tell you exactly what I changed to make it stop working, but I don't recall. I made edits to the query and the form. One thing I recall is trimming down the fields shown on each row of the form. I'm not sure if removing fields from the form could could cause this though? I also removed fields from the query, but the field asking for a parameter is still there.

Any ideas? I understand this is very vague and there's no way to give a step by step exact answer, but maybe there's a basic idea I could look for?
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 05:32
Joined
Jan 14, 2017
Messages
18,209
It sounds like you need to add delimiters to the filter criteria in the where clause.
Please post the sql used for the record source
 

isladogs

MVP / VIP
Local time
Today, 05:32
Joined
Jan 14, 2017
Messages
18,209
From your rep comments am I correct in thinking this is now solved?
If so, would you like to mark the thread as SOLVED
 

MattCSI

New member
Local time
Yesterday, 23:32
Joined
Jan 10, 2019
Messages
2
I believe it is solved now. I'm a beginner, and working a database designed by someone else, so I'll do my best to explain what was happening.

A form called frmOPR is based on a query named qryOPR.


There are various buttons which open frmOPR with different filters. Each button has its own VBA code to feed the form a different query for the filtering - examples:
DoCmd.OpenForm "frmOPR", , "qryBid"
DoCmd.OpenForm "frmOPR", , "qrySales"
DoCmd.OpenForm "frmOPR", , "qryNotAwarded"


The problem was that I was editing the individual queries (qryBid, qrySales, etc), but I hadn't edited the query the form is based on (qryOPR). qryOPR was missing some of the fields I was filtering in qryBid, so it was having problems when trying to apply them to the form.

This all came from my lack of understanding of how the form was created. Reading your suggestion made me check the record source, which lead me to see the form was based on another query and realize the problem.

I will mark this solved. Thank you for your help!
 

Users who are viewing this thread

Top Bottom