Openform "where" problem

D

Dick Minter

I am opening a form in either data entry mode or a filtered view, using
docmd.openform to set the mode and filter.

Dim stName As String
Dim lchoice As Long

lchoice = Me!choice.Value
stName = "accruals"
If lchoice = 1 Then
DoCmd.OpenForm stName, acNormal, , , acFormAdd
Else
DoCmd.OpenForm stName, acNormal, , "[mthend] = #03/31/2006#"
End If

Problem: With the filter option, the records appear in the form in an odd
order. I would expect them to appear in key field order as they do without
the filter. Why that result? Is there a better approach to applying the
filter, or should I add a sort to the form open event?

DM
 
K

Klatuu

There is not arguement for ordering a recordset in the Openform method. You
will have to set the OrderBy property in the form itself.
 
S

stefan hoffmann

hi Dick,

Dick said:
Problem: With the filter option, the records appear in the form in an odd
order. I would expect them to appear in key field order as they do without
the filter. Why that result?
The order clause may force the optimizer to use an index. In this case
the index order is used, otherwise the resulting order is a mix between
the primary key order and the filter operation.
Is there a better approach to applying the
filter, or should I add a sort to the form open event?
If order is an issue, set the order always with Me.OrderBy and
Me.OrderByOn in the appropriate events (on load, on command button click).


mfG
--> stefan <--
 
Top