Passing Variable vaule to a report

A

Alain

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
DoCmd.OpenReport.

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
exist......"

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
view.
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

Thanks

Alain
 
G

George Nicholson

1) Consider the addition of proper error handling:

Sub MySub()
On Error GoTo ErrHandler

DoCmd.OpenReport stDocName, acPreview, , strCond

With Reports![rpt-GlobalCieList]
......
ExitHere:
Exit Sub
ErrHandler:
Select Case Err.Number
Case 2051
'Ignore: No Data
GoToExitHere
Case Else
MsgBox Err.Number & " " & Err.Description
GoToExitHere
End Select
End Sub

And/Or
2) Consider using a different IsLoaded routine that doesn't limit you to
Forms. This one returns True rather than False if a form is open in design
mode. The one you are using could be renamed FormIsLoadedNonDesignMode.

If IsLoaded("rpt-GlobalCieList",acReport) Then
.........

Public Function IsLoaded(strObjName As String, Optional lngObjType As
acObjecttype = acForm) As Boolean
' Returns True if strName is Open (non-zero), False(0) otherwise.
' Should return 0, not an error, if the object doesn't exist. *Subforms
always return False*
' Default Object is Form
On Error Resume Next
IsLoaded = (SysCmd(acSysCmdGetObjectState, lngObjType, strObjName) <> 0)
End Function

HTH,
--
George Nicholson

Remove 'Junk' from return address.


Alain said:
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
DoCmd.OpenReport.

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
exist......"

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
view.
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

Thanks

Alain
 

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

Similar Threads

Passing Variable value to a report 2
Passing variable value 3
Function Name problem 5
Compile Error: Variable Not Defined 2
isloaded help. 2
Why do I get Runtime Error 2501? 2
HELP 6
Problem with Parameter Form 4

Top