Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Access can't find the field 'forms' ref to in your expressio 1

Status
Not open for further replies.

fredk

Technical User
Jul 26, 2001
708
US
I am creating a database in access 2000 - infrequently, I am getting the error:

Microsoft Access can't find the field 'forms' referred to in your expression

I get this error message when I click a button to run a report - The queries do have filters that refer to the selection on the form.

Strange thing is that it happens sometimes but not all of the time - Any ideas would be greatly appreciated !!!

Thanks!!!!

Fred
 
Actually, I am still gettng the error - the command button is created from the wizard:

Private Sub Command40_Click()
On Error GoTo Err_Command40_Click

Dim stDocName As String

stDocName = "rptSpecificAcctConsActivity"
DoCmd.OpenReport stDocName, acPreview

Exit_Command40_Click:
Exit Sub

Err_Command40_Click:
MsgBox Err.Description
Resume Exit_Command40_Click

End Sub
 
You said the queries have filters that refer to the selection on your form? That may be your problem. I'm guessing in your queries, you have criteria that look similar to this...Forms!YourForm!YourField.

To get around this, here's what you do...create a code module (or use an existing one if you have it). Add a Global variable for each of parameters you want to pass from your form to your queries. Then, create a function for each Global variable that simply returns the value of your Global variable...

Code:
Global g_strGlobalVariable1 as String

Public Function GetGlobalVar1() As String
   GetGlobalVar1 = g_strGlobalVariable1
End Function

Then, in your queries, reference your Functions instead of your form fields.

Good Luck!
 
I forgot one thing...in your form, before you open the report, set the Global variables to the values on your form.
Code:
g_strGlobalVariable1 = Me.txtVariable1.Value
 
Great - thanks for your help!!!!!!


Fred
 
Just one more question.

Is there another way to do this? I have 6 different fields that I use so I would have to make one up for each field. I am confused because this never was a problem before???

Also, the reports run most of the time, it is just occasionally that I have the problem.

Thanks!!

Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top