View Full Version : Choice of Criteria from two forms


Becca
02-27-2002, 01:04 PM
Can anyone tell me if it is possible to set the criteria in a query so it will look at one form if it is open, for the criteria, or lookk at the other form for the criteria if it is open. It will be the same feild in each form that will have to be looked up.
Using an OR statement seems to make it look at both, but will ask for parameter entry if one is closed.

Pat Hartman
02-27-2002, 07:56 PM
You can only reference a form if it is open. A way around the problem is to create a public variable and a public function that returns the value you need.

Global YourPublicVariable As String (or whatever)

Public Function SomeFunctionName() As ...
SomeFunctionName = YourPublicVariable
End Function

Then in each form, prior to opening the query, assign a value to YourPublicVariable. In the query:

Select ...
From ...
Where SomeField = SomeFunctionName();

Becca
02-27-2002, 10:23 PM
Thanks for the suggestion Pat

I am still having a bit of an issue though. This is the error message I now get from my queries:

"The specified field [reference] could refer to more than one table listed in the FROM clause of your SQL statement"

The field I am using is [reference] in the criteria of the query.My code entered is:

Global yourpublicvariable As String

Public Function somefunctionname() As Reference
somefunctionname = yourpublicvariable
End Function

I wasn't quite sure where to whack this, as I am DIY access student, and so I put it in a general module, could this be my problem?
I have been wary of changing much else in the terminaology as I just want this to work.

Pat Hartman
02-28-2002, 05:34 AM
You could use meaningful names for the function and public variable http://www.access-programmers.co.uk/ubb/smile.gif

Since you defined the variable as string, the function should return a string variable:

Public Function somefunctionname() As String

Becca
02-28-2002, 01:46 PM
Thanks Pat
My even-less-than-amateur status shines through I think.
I guess I am a little confused as to what the feilds should represent:

* Is string appropriate to define in the statement Global Reference as String

*Is the field "YourPublicVariable" just the field I want to return from the form, ie Reference

*The "someFunctionName' field just loses me completely, any ideas about what function is appropriate?

Thanks For your help

Becca
02-28-2002, 06:26 PM
Pat

Thanks for your help. I ended up getting around the whole issue by combining everythign onto the one form. So far so good.