Can I use a variable in my OrderBy Property?

G

Guest

Hi,

I have a function which uses a variable called "qrySort" to concatenate the
sort order for a search query I've created. I am trying to apply this to my
form using:

forms![Main]![Contact].form.OrderBy = "(my qrySort variable)"

Problem is I don't know how to pass the variable using the right syntax or
if this is even possible. I've tried " & qrySort & " but that doesn't work.
It seems like .OrderBy takes whatever is in the " marks literally and doesn't
consider the variable value.

Is there some way to do this? I know I can do it with the form's
RecordSource property but I'm trying to use a Filter instead which would
require setting the OrderBy property.

Man I wish Access Help did a better job of explaining these things.

Thanks,

Bill
 
D

Dirk Goldgar

Bill Mitchell said:
Hi,

I have a function which uses a variable called "qrySort" to
concatenate the sort order for a search query I've created. I am
trying to apply this to my form using:

forms![Main]![Contact].form.OrderBy = "(my qrySort variable)"

Problem is I don't know how to pass the variable using the right
syntax or if this is even possible. I've tried " & qrySort & " but
that doesn't work. It seems like .OrderBy takes whatever is in the "
marks literally and doesn't consider the variable value.

Is there some way to do this? I know I can do it with the form's
RecordSource property but I'm trying to use a Filter instead which
would require setting the OrderBy property.

Man I wish Access Help did a better job of explaining these things.

Thanks,

Bill

So you have a string variable named "qrySort", which has been set to
valid ORDER BY clause (without the words "ORDER BY")? Did you try just
executing this line of code:

Forms!Main!Contact.Form.OrderBy = qrySort

?
I take it that Contact is the name of a subform control on form Main.
 
S

Sandra Daigle

Hi Bill,

You don't need any quotes:

forms![Main]![Contact].form.OrderBy = qrySort
 

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

Similar Threads


Top