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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Me!' syntax running a query from a form.

Status
Not open for further replies.

postmanphat

Technical User
Nov 13, 2006
117
GB
MERRY CHRISTMAS!

I want to be able to run one query from various different forms. So for the criteria in the query design grid I've tried various combinations of

[Me].[Forms].[AppID]
[Forms]![Me]![AppID]

and so on, but none work. All the forms in question have the AppID field.

Its been a while since I've really used Access and know this is possible but I'll be damned if I can remember it!

Many thanks in advance people!
 
For a query to reference a control on a form the syntax is:

Code:
Forms!FormName!ControlName

If you're running the same query from multiple forms that will be a little more complex.

Perhaps you could return the value in a public function and reference the function in your query instead:

Code:
Public Function RetVal(ByVal strFormName as string, ByVal strControlName as string)
    RetVal=Forms(strFormName).Controls(strControlName).Value
End Function

Ed Metcalfe.

Please do not feed the trolls.....
 
Alternatively you could use a parameter query and pass your value to the parameter in code before running the query...

Ed Metcalfe.

Please do not feed the trolls.....
 
Is there not a way though of using

Forms!Me!ControlName

to reference a control on whatever the active, open form is?
 
Not if you're using it in the query. At least not that I'm aware of.

I'm sure somebody's going to prove me wrong now... :-)

Ed Metcalfe.

Please do not feed the trolls.....
 
try

Code:
select * 
from tablename
where fieldname=[screen].[ActiveForm]![controlname]

but you must run this from thr form

i.e.
on button click

docmd.openquery "queryname
 
If the query is the record source for a form or report and the [AppID] field is in the record source, then I would remove the form/control reference from the query and use the where condition argument of the DoCmd.OpenReport method. This would make your query less dependent on a form or forms.

Duane MS Access MVP
Now help me support United Cerebral Palsy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top