Me! Not working in Query?

G

g

Hi again,

I have a query with criteria base on a control from a form.

WHERE ColumnName=[Forms]![FormMain].[ControlName]

It works perfectly fine but for some reason I have to make a duplicate copy
of
the FormMain and name it like FormMain2. So right now I have 2 forms that
will perform the same query.

Now, I tried to change the criteria into [Me]![ControlName] but it didn't
work.

Am I missing something or is it really not possible in a query. If not what
should I do?

Thank you
G
 
R

*raul*

You can try

".. WHERE ColumnName=" & Me![ControlName] & ";"

Or, considering the value will be a string, adding single quotes
around it:

".. WHERE ColumnName='" & Me![ControlName] & "';"


The idea is to force calculation separately, before the insertion in
the string.
 
J

Jeanette Cunningham

Hi,
with the query set up to reference the form like this:
[Forms]![FormMain].[ControlName]

you need a second query with criteria like this:
[Forms]![FormMain2].[ControlName]

for the second form.

Jeanette Cunningham
 
K

Ken Sheridan

You can't use Me in a query, only in VBA. Strictly speaking it refers to the
current instance of a class, but think of it as the current form or report in
whose module the code is executing.

If you are opening the query, or a form or report based on it, from the form
containing the referenced control you could add a function such as the
following to a standard module:

Public Function GetValue(strCtrl As String)

GetValue = Screen.ActiveForm.Controls(strCtrl)

End Function

And call it like so:

WHERE ColumnName = Getvalue("ControlName")

Ken Sheridan
Stafford, England
 
G

g

Thank you for all the suggestions. This site is really helpful to everyone
working with access.

Jeanette Cunningham said:
Hi,
with the query set up to reference the form like this:
[Forms]![FormMain].[ControlName]

you need a second query with criteria like this:
[Forms]![FormMain2].[ControlName]

for the second form.

Jeanette Cunningham


g said:
Hi again,

I have a query with criteria base on a control from a form.

WHERE ColumnName=[Forms]![FormMain].[ControlName]

It works perfectly fine but for some reason I have to make a duplicate
copy
of
the FormMain and name it like FormMain2. So right now I have 2 forms that
will perform the same query.

Now, I tried to change the criteria into [Me]![ControlName] but it didn't
work.

Am I missing something or is it really not possible in a query. If not
what
should I do?

Thank you
G
 
Top