Pass variable from form to Query ...

M

Me

Is there any way by which I can pass a public variable value to
a query?

I have a form with Public variable as -

Public myqueryvar as String

I would like to use this variable in my query

Thank you,
-Me
 
D

Douglas J. Steele

Queries don't know anything about variables. You have to create a function
that'll return the value:

Public Function MyFunction() As String

MyFunction = myqueryvar

End Function
 
M

Me

Hi Douglas,

Please excuse me for my ignorance.
Where do I create this function?
In a query when I try to create a function I get error.
I have created it in a form, but then when I call it in query, it doesn't
recognize it.

Thank you,
-Me
 
D

Douglas J. Steele

It needs to be created in a module, not in the code behind a form (or
report).
 
A

awstyle

Me said:
Is there any way by which I can pass a public variable value to
a query?

I have a form with Public variable as -

Public myqueryvar as String

I would like to use this variable in my query

Thank you,
-Me

Hi Me!

What, exactly, are you trying to do? Are you setting up a form into which you
can type or select of parameter which is then used in your query?

If so, what I do is set up the form with a text box or a self populating
combo box (whatever) and then add a button to run a query or a report based
on a query. You then refer to the form's control as your selection criteria
in the query.

For example, say you want to produce a report/query based on people who are
male.

Create a form, say, frmMySelection with a text box (txtGender).

In the query's criteria you insert [Forms]![frmMySelection]![txtGender] into
the Gender column.

Hope this helps.

Kind regards

Tony
 
M

Me

Hi Tony,

Doug 's replies helped me resolve my issue.
Your suggestion is great, I will definitely keep it in mind when I need that
kinda functionality.

Appreicate your help!
-Me


awstyle said:
Me said:
Is there any way by which I can pass a public variable value to
a query?

I have a form with Public variable as -

Public myqueryvar as String

I would like to use this variable in my query

Thank you,
-Me

Hi Me!

What, exactly, are you trying to do? Are you setting up a form into which you
can type or select of parameter which is then used in your query?

If so, what I do is set up the form with a text box or a self populating
combo box (whatever) and then add a button to run a query or a report based
on a query. You then refer to the form's control as your selection criteria
in the query.

For example, say you want to produce a report/query based on people who are
male.

Create a form, say, frmMySelection with a text box (txtGender).

In the query's criteria you insert [Forms]![frmMySelection]![txtGender] into
the Gender column.

Hope this helps.

Kind regards

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top