sort data from form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, i am trying to create a code where when the user presses a button,
depending on which option button is chosen the report based on a query will
be shown in ascending order by Date Set (one field) or by Date Due (another
field). so on the form i have a group of option buttons. if the first option
is selected the report will be ordered by the DAte Set field in the query,
and if hte second option button is selected the report will be sorted by the
field called Date Due. i thought the best way to do this would be to use a
select command and use the order by function. is this right ... however i am
new to coding and dont think i have done this rite .. any help would be much
appreciated.

code:


' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "Homework") <>
acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build user option for Sort Criteria

If SortOptionGroup.Value = "1" Then
strSort ="SELECT [*] FROM [qryHomework] ORDER BY [DateSet]"
DoCmd.RunSQL strSort
Else
strSort = "SELECT [*] FROM [qryHomework] ORDER BY [DateDue]"
DoCmd.RunSQL strSort
End If


any ideas would be welcome. thanks
 
kishan said:
hi, i am trying to create a code where when the user presses a button,
depending on which option button is chosen the report based on a query will
be shown in ascending order by Date Set (one field) or by Date Due (another
field). so on the form i have a group of option buttons. if the first option
is selected the report will be ordered by the DAte Set field in the query,
and if hte second option button is selected the report will be sorted by the
field called Date Due. i thought the best way to do this would be to use a
select command and use the order by function. is this right ... however i am
new to coding and dont think i have done this rite .. any help would be much
appreciated.

code:


' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "Homework") <>
acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build user option for Sort Criteria

If SortOptionGroup.Value = "1" Then
strSort ="SELECT [*] FROM [qryHomework] ORDER BY [DateSet]"
DoCmd.RunSQL strSort
Else
strSort = "SELECT [*] FROM [qryHomework] ORDER BY [DateDue]"
DoCmd.RunSQL strSort
End If


You can't do that kind of thing once the report has started
(open). Another issue is that if the report has anything
specified in its Sorting and Grouping window or uses an
aggregate function (Count, Sum, etc), then the sorting in
the report's record source query is ignored/overridden by
the Sorting and Grouping settings.

You can modify existing GroupLevel properties in the
report's Open event procedure.

If you have nothing at all in the report Sorting and
Grouping window, then you can specify the report's sorting
by constructing the report's record source SQL statement as
I suggested in your other thread. This is not recommended,
because you will have to redo everything if you ever need to
use grouping, etc.
 
Back
Top