The situation
My database contains several queries and a form, let's call them Query1a, Query1b, and Query2, and Form1.
Form1 contains controls Text1, ComboBox1, and a button Command1.
Queries 1a and 1b reference controls on Form1 explicitly, e.g. via a SELECT Forms!Form1!Text1 as Expr1. Query2 depends on Queries 1a and 1b.
Command1 runs DoCmd.OpenQuery "Query2" on click, and everything works fine.
The Problem
I have various forms with structures similar to Form1, and I'd like to put them all in a navigation tab. I go to create -> navigation -> horizontal tabs and drag Form1 to a tab.
Now, when I try to use the Form1 in the navigation form, Access pops up and asks me for the value of Text1, because Query1a is trying to look for it in Forms!Form1 but my Text1 really lives in Forms!NavigationForm!Form1.Form.
Attempts
I could go into each of the queries and change the code to explicitly reference the subform, but that's tedious, not very elegant, and it would break the ability to use the form outside of the navigation form.
Inspired by the comments, I also tried the following:
- Add a PARAMETERS declaration to
Query1aandQuery1b - In my button in
Form1, I set the parameters programmatically viaQueryDef. This way, I can do something likeDim qdf As DAO.QueryDef Set qdf = CurrentDb.QueryDefs("Query1a") qdf.Parameters("Forms!Form1!myparam").Value = Me!Text1
However, I don't know where to go from there, as my QueryDef object is invisible to Query2.
One thing that would make life easier is to have the queries be able to reference the form object from where they are called, but I don't know if that's possible.