Can I use a variable in my OrderBy Property?

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
Back
Top