Ordering reports based on condition.

szymek_d

Registered User.
Local time
Today, 09:56
Joined
May 26, 2005
Messages
21
hi.

i'm trying to order a report based on a condition selected in a form that calls the report.
for instance

'builds whereCondition

varWhere = (varWhere + " AND ") & _
"[field1] IN (Select field1 From tbl1, tb2 " & _
" WHERE tbl1.field3 = tbl2.field4)"


'this is list that has several field based on which the report will be ordered once opened. (But it doesn't work, i get a syntax error)
If Me!Order_List = "Last Name" Then
varWhere = (varWhere + " ORDER BY fld5")
End If

DoCmd.OpenReport "rptContacts", acViewPreview, , Wherecondition:=varWhere

I sure that the building of the first varWhere is good cuz it works once i take out the second one. (ORDER BY)

Is what i'm doing possible? please give me some advice.
 
Last edited:
sz,

The 4th clause of the OpenReport does nothing for the sort order. It is
used only to select which records to include.

DoCmd.OpenReport "rptContacts", acViewPreview, , varWhere

If you want dynamic sorting, you'll have to look at QueryDefs. Build a
query (which includes sorting) and pass it to a report that doesn't sort.

Use the Search Facility here and look for "QueryDef".

Wayne
 
Once again... thank you for pointing me in the right direction Wayne!!
I'm playing around with queryDefs right now.
 

Users who are viewing this thread

Back
Top Bottom