Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / December 2005

Tip: Looking for answers? Try searching our database.

Passing Variable vaule to a report

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alain - 05 Dec 2005 19:22 GMT
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
George Nicholson - 05 Dec 2005 20:01 GMT
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,
Signature

George Nicholson

Remove 'Junk' from return address.

> Hi to all,
>
[quoted text clipped - 57 lines]
>
> Alain
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.