Passing Variable value to a report



Hi to all,

I have build a report that is dynamic build by the user. My problem is the
Order By criteria of the report.
On my form command button to open the report I have a strSort variable that
is used to build my Order By string.
On the command button I use the following to open the report:

DoCmd.OpenReport stDocName, acPreview, , strCond
If Err.Number = 2501 Then Err.Clear

'application du sorting au rapport
With Reports![rpt-GlobalCieList]
.OrderBy = strSort
.OrderByOn = True
End With
Reports![rpt-GlobalCieList]![Label2].Caption = "( Sorted by: " &
strShow & " )"

On that report, I have the NoData event being fired when there is no data to
display since there was new fields added for the criteria selection. I close
the report at the NoData event (cancel = true) so the user is being send
back to the form to make modification to the report. Now when I do that I
get error "2501 The open report action was Cancelled" at he

After some testing I was able to find a solution for this, I close the
report window at the Report_Activate or at the Report_Page which is working
just fine but I run into another error "2451 Report is not open or does not

Can passing my variable string to the Report_Open or Report_Activate ( where
I apply the OrderBy) solve my problem ??? or is there anything else I can do
to correct this.

Is there a way to find if a report is open, I have tried the IsLoaded
function but it works only on forms:

Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question