Change Sort in VB

  • Thread starter Thread starter Nancy
  • Start date Start date
N

Nancy

how can I run one report with various sorts based on the cmdButton a user
clicks.
Here is my current code which is behind several cmdButtons that use criteria
from a text box.

-- Dim sWhereClause As String
Dim sOpenARgs As String

stDocName = "MasterDeposition_SC"
Me.Depo.SetFocus
If Me.Depo.Text <> "" Then
sWhereClause = "Depo Like [Forms]![ReportsMain]![Depo]"
sOpenARgs = "Master Deposition For Deponent of the xxxxx Firm,
L.L.C. for: " & Me.Depo.Text
DoCmd.OpenReport stDocName, acPreview, , sWhereClause, , sOpenARgs

Else
sOpenARgs = "Master Deposition of the xxxxxFirm, L.L.C. for All
Deponents"
DoCmd.OpenReport stDocName, acPreview, , , , sOpenARgs
End If
nancye
 
Nancy said:
how can I run one report with various sorts based on the cmdButton a user
clicks.
Here is my current code which is behind several cmdButtons that use criteria
from a text box.

-- Dim sWhereClause As String
Dim sOpenARgs As String

stDocName = "MasterDeposition_SC"
Me.Depo.SetFocus
If Me.Depo.Text <> "" Then
sWhereClause = "Depo Like [Forms]![ReportsMain]![Depo]"
sOpenARgs = "Master Deposition For Deponent of the xxxxx Firm,
L.L.C. for: " & Me.Depo.Text
DoCmd.OpenReport stDocName, acPreview, , sWhereClause, , sOpenARgs

Else
sOpenARgs = "Master Deposition of the xxxxxFirm, L.L.C. for All
Deponents"
DoCmd.OpenReport stDocName, acPreview, , , , sOpenARgs
End If


You can change (not add or delete) the sorting/grouping in a
report by using code in the report's Open event procedure to
(re)set the desired GroupLevel elements.

Me.GroupLevel(0).ControlSource = Forms!theform.sometextbox

where sometextbox is the form text box set to the name of
the field to be used for sorting. Be sure to set a sort
level in the report's design view. Check GroupLevel in VBA
Help for details.
 
Back
Top