The information in this article applies to:
- Microsoft Access versions 1.0, 1.1
SYMPTOMS
The message
Invalid reference to field 'Field Name' in query
occurs when you are printing or previewing a graph from Form view, or when
you are printing a graph on a report from print preview.
CAUSE
The data source for the graph is a parameter query. The parameter query is
run one time to collect the values required to display the graph in Form
view or print preview. Once the parameters are collected through the Enter
Parameter Value box, they no longer exist. When you try to print the graph,
the graph must be regenerated from the underlying data. Since the
parameters are no longer available and are not prompted for again, the
error message stated above is generated.
RESOLUTION
Rather than enter the parameters using the Enter Parameter Value box, the
parameters for the query should come from a source that is available while
the form is active. Modify the query so that the parameters are referenced
directly from a second form.
The following example demonstrates how to use a second form to collect the
values:
- Open the sample database NWIND.MDB. Create a blank, unbound form called
Parameter Form with the following controls and properties:
Form: Parameter Form
Text box
ControlName: Beginning Date
Text box
ControlName: Ending Date
Command button
Caption: Open Graph Form
OnPush: Graph Form.Open
- Create a new macro called Graph Form with the following actions:
MacroName Action Defined Below
-------------------------------------------
Open SetValue 1
OpenForm 2
Close Close 3
Graph Form Actions
------------------------------------------
1. SetValue
Item: Forms![Parameter Form].Visible
Expression: False
2. OpenForm
Form Name: Graph Form
View: Form
Filter Name: <leave empty>
Where Condition: <leave empty>
Data Mode: Edit
Window Mode: Normal
3. Close
Object Type: Form
Object Name: Parameter Form
- Open the Employee Sales By Country (Parameter) query in Design view.
- Change the criteria row for the Shipping Date column from
Between [Beginning Date] And [Ending Date]
to:
NOTE: In the following example, an underscore (_) is used as a line-
continuation character. Remove the underscore when re-creating this
example.
Between Forms![Parameter Form]![Beginning Date] And _
Forms![Parameter Form]![Ending Date]
- From the Query menu, choose Parameters. Change the parameters to be:
Parameter Data type
------------------------------------------------------
Forms![Parameter Form]![Beginning Date] Date/Time
Forms![Parameter Form]![Ending Date] Date/Time
NOTE: Your query may not have parameters explicitly defined in the
Parameters dialog box; however, it is good practice to do so.
- Open the Graph Form and alter the OnClose property to be:
OnClose: Graph Form.Close
- Open the Parameter Form form and type "1/1/92" (without the quotation
marks) in the first box, and type "12/31/92" (without the quotation
marks) in the second box. Choose the Open Graph Form button.
Note that when you choose the Open Graph Form button, a macro hides the
parameter form and then opens the graph form. Although the parameter
form is hidden, it is still open, and the values on it are still
available for the query that the graph is based on.
- From the File menu, choose Print Preview.
Because the parameter form remains open, and the values on it are still
available, the graph can be regenerated for printing. In contrast, the
Enter Parameter Value box values are available only at the time the
parameter is entered.
STATUS
Microsoft has confirmed this to be a problem in Microsoft Access versions
1.0 and 1.1. This problem no longer occurs in Microsoft Access version 2.0.
MORE INFORMATION
Steps to Reproduce Problem
- Open the sample database NWIND.MDB. Create a blank, unbound form and
save it with the name Graph Form.
- Click the graphing tool in the toolbox, and then click in the blank
form to start the GraphWizard.
- In the "Also, Select a Data Source for Your Graph" box, select
Employee Sales By Country (Parameter).
- Choose Next to advance to the next screen.
- In the Available Fields box, select Sale Amount. Choose the ">" button
to add it to the Fields For Graph box.
- In the Available Fields box, select Salesperson, and then choose ">".
- Choose Next to advance to the next screen.
- Choose the Design button.
- From the View menu, choose Form.
- Type "1/1/92" (without the quotation marks) in the Beginning Date
parameter value box, and then choose OK.
- Type "12/31/92" (without the quotation marks) in the Ending Date
parameter value box, and then choose OK. A bar graph will be displayed.
- From the File menu, choose Print Preview.
The error message: "Invalid reference to field 'Beginning Date' in
query" will be displayed.
|