Using value from forms in a query

Jen 20 Reputation points
2025-10-02T17:05:00.3866667+00:00

I have several different data tables that use Project Number. I'm gathering data from the different tables and putting into one local table. I set up a form and used a text box for entering project numbers.....I have 2 different ones so I can enter two different numbers. In the different queries I use the criteria for the Project Number as

[Forms]![ProjectForm]![Number1] or [Forms]![ProjectForm]![Number2]

Where 'ProjectForm' is the name of my form and 'Number#' are the NAME of the text boxes as shown in the property sheet of the form.

The above critiria works in some queries, but not others. Seems to work when I was going against network tables, but not going against the local table. What am I missing?

The error message I get is as follows: The Microsoft Access database engine does not recognize '[Forms]![ProjectForm]![Number1]' as a valid field name or expression.

Microsoft 365 and Office | Access | Other | Windows
0 comments No comments
{count} votes

Answer accepted by question author
  1. Karl Donaubauer 2,696 Reputation points MVP
    2025-10-03T10:34:28.5466667+00:00

    Hi,

    This error message happens when a crosstab query is involved, i.e. when the query where you use the parameters is a crosstab or when it uses a crosstab as source. To solve this you have to explicitely declare the parameters:

    In query design view go to the Query Design ribbon tab and far on the right choose the Parameters icon. In the Parameter column use [Forms]![ProjectForm]![Number1] and in the Data Type column choose the correct type from the dropdown. Do the same for the second parameter.

    Servus
    Karl


    Access Forever News DevCon
    Access-Entwickler-Konferenz AEK 18.+19.10. Nürnberg


2 additional answers

Sort by: Most helpful
  1. Duane Hookom 26,555 Reputation points Volunteer Moderator
    2025-10-02T17:21:23.9633333+00:00

    Can you confirm the form is always open when the query is run? Have you attempted to open the immediate window (press Ctrl+G) and enter:

    ? [Forms]![ProjectForm]![Number1]

    1 person found this answer helpful.

  2. TiNo-T 9,275 Reputation points Microsoft External Staff Moderator
    2025-10-03T00:28:30.6233333+00:00

    Dear @Jen

    Welcome to Microsoft Q&A Forum! 

    Thank you for your follow-up regarding the issue with referencing form controls in your Access queries. I appreciate your confirmation that the form is open when the query runs. Based on your description and the error message, I’d like to provide some insights and recommendations, along with official Microsoft documentation links to help you can consult for each point and see if they can help you in this case: 

    1.I want to state that your form must be opened and accessible. Even though the form is open, Access requires it to be actively loaded and accessible when the query runs. If the form is hidden or not fully initialized, Access may fail to resolve the reference. I found that Microsoft mentioned this behavior in the note here, you can take a look if it can help: Create a control that references a control on another form - Microsoft Support 

    2.Because I saw that you mentioned using Ctrl+G to open the Immediate Window. That’s a great way to test whether the form and its controls are accessible. When the Immediate Window opens, make sure you're in the VBA editor, and the form is open in Access. Also, you may try typing this in the Immediate Window: 

    ?Forms!ProjectForm!Number1 
    

    If the control is accessible, it will return the current value. If not, it may indicate a typo or that the form/control isn't properly loaded. So, you should check it. 

    3.I found an idea as alternative method: if referencing form controls directly continues to cause issues, you may try using TempVars as a more stable alternative. These are global variables that can be set from the form and used in queries without requiring the form to remain open. Microsoft explains TempVars and you can consult it here: SetTempVar Macro Action - Microsoft Support 

    For an example usage in a query: 

    [TempVars]![Number1] Or [TempVars]![Number2]
    

     4.If Access cannot resolve the form reference, it may prompt for a parameter or show an error like: "The Microsoft Access database engine does not recognize...". This typically means Access cannot find the form or control at runtime. You can take a look in these articles: 

    5.Microsoft also recommends using forms to collect parameters for queries, which can help streamline user input and avoid runtime errors. You can consult here: Use parameters in queries, forms, and reports - Microsoft Support 

    I hope this information can help you in this case and please kindly correct me if I misunderstand your concern. Wish you a pleasant day! 


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.