Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Orderby - List Null Values last

Status
Not open for further replies.

Vittles

Programmer
Dec 7, 2000
95
US
I have a form that has a toggle button in a subform that changes which subform shows up and the related sort order (among a bunch of other formatting options).

The orderby section (form open event) looks like this:
If Forms![Main Review Form]![View Type Subform].Form!View = True Then
Me.OrderBy = "Inst Name"
Me.OrderByOn = True
Else
If Forms![Main Review Form]![View Type Subform].Form!View = False Then
Me.OrderBy = "LOI Inst Name"
Me.OrderByOn = True
End If
End If
End Sub

I would like to take this one step further in that if there are null values in the 'orderby' field I would like those records to show up last in the order.

I know that in reports you can group & then order records like this using a formula like the following: =IIf([LNames]>"",1,2)

Is there a similar code for forms?
 
Much the same thing should work here
Code:
Me.OrderBy = "IIF(IsNull([LOI Inst Name]), "1", "2" & [LOI Inst Name])
 
This variation doesn't work - is it correct? Also, wouldn't the IsNull(Inst Name]) criteria put those that are null first in line not at the end?

If Forms![Main Review Form]![View Type Subform].Form!View = True Then
Me.OrderBy = "IIf(IsNull([Inst Name]), "1", "2" & [Inst Name])"
Me.OrderByOn = True
Else
If Forms![Main Review Form]![View Type Subform].Form!View = False Then
Me.OrderBy = IIf(IsNull([LOI Inst Name]), "1", "2" & [LOI Inst Name])
Me.OrderByOn = True
End If
End If
End Sub

Help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top