We help IT Professionals succeed at work.

requery a report

samj
samj asked
on
Medium Priority
839 Views
Last Modified: 2013-11-28
access 2000 report

        If IsLoaded("rptTransGroups") = True Then
            DoCmd.Close acReport, "rptTransGroups"

so that I can reopen the report with new criteria

Function IsLoaded(ByVal strObjName As String) As Integer
' Returns True if the specified form is loaded.
   
    Const conDesignView = 0
    Const conObjStateClosed = 0

    IsLoaded = False
    If SysCmd(acSysCmdGetObjectState, acForm, strObjName) <> conObjStateClosed Then
        If Forms(strObjName).CurrentView <> conDesignView Then
            IsLoaded = True
        End If
    End If
    If SysCmd(acSysCmdGetObjectState, acReport, strObjName) <> conObjStateClosed Then
        If Reports(strObjName).CurrentView <> conDesignView Then <<<<<<<<<<<<<<<<<<
            IsLoaded = True
        End If
    End If

End Function

The line in <<<<<<<<<< above is giving me
Run time error 2465      
Application defined or object defined error.

The report is open already but I need to roguery it since its data are based on a query. So how do I do that, is there a report roguery or close and reopen? And how to fix this?
Thanks
Comment
Watch Question

Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
samj,

If the Report is based on a query, then every time you open it, it refreshes and displays the most current data.

So unless you are leaving the report open on the screen for "Hours" at a time, I don't see the need to refresh it.

That being said, ...In Access 2007 there is a "Refreh All" button that will refresh (requery) the Report on demand.

In Access 2003 and earlier, you may just have to close then re-open the report.

JeffCoachman
Commented:
Reports do not have a current view, and cannot be re-queried. You need to close and reopen. From an interface point of view, it makes little sense to test for design view. If you are designing the report, you would not run the same code anyway, would you?

It looks as though you are trying to adapt something that works for forms and use it for reports, but they are quite different beasts. Do not mix form and report management in the same function, it's only confusing.

(°v°)
    Const RPT_NAME = "rptTransGroups"
 
    If SysCmd(acSysCmdGetObjectState, acReport, RPT_NAME) Then _
        DoCmd.Close acReport, RPT_NAME
    DoCmd.OpenReport RPT_NAME, acViewPreview

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
Hi Jeff. I don't know much about Access 2007... is there an equivalent RunCommand constant, too?

(°v°)

Author

Commented:
I am getting Run time error 3078, at the line is marked below.

        Const RPT_NAME = "rptTransGroups"
        If SysCmd(acSysCmdGetObjectState, acReport, RPT_NAME) Then
            DoCmd.Close acReport, RPT_NAME
            DoCmd.OpenReport RPT_NAME, acViewPreview, , crit
        Else
            DoCmd.OpenReport RPT_NAME, acViewPreview, , crit <<<<<<<<<<<<<<<<<<<<<<<
        End If


?crit
[TrnsDate] >=#02-01-2002# AND  [TrnsDate] <= #02-28-2002#

Commented:
Error 3078 is "The Microsoft Jet database engine cannot find the input table or query"... This would mean your report doesn't work at all at the moment... Does it? Can you open it from the interface? Does it work without the criteria (which is perfectly correct, assuming there is a field TrnsDate in the report's record source)?

(°v°)
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
harfang,

" is there an equivalent RunCommand constant, too?"

I could not find any.
I tried these:
(which may or may not be the same in Access 2003 and lower)

    'DoCmd.RunCommand acCmdRefresh
    'DoCmd.RunCommand acCmdRefreshData
    'DoCmd.RunCommand acCmdRefreshPage
    'DoCmd.RunCommand acCmdDiscardChangesAndRefresh

... and none refreshed the report, the only thing that dynamically refreshed the report was clicking the "Refresh All" button from the Records "chunk" in Accecess 2007.

Jeff

Commented:
Jeff,

Perhaps Access 2007 does it like we did here: close and reopen the report? On the other hand, there are so many acCmd constants, it's hard to get an overview. I sometimes copy-paste the entire list of constants from help to a text editor, just so I can search for key words among them...  I should really take the time to study that version a bit...

samj,

I take it you found what was wrong with the report. Kudos and success with your project!
(°v°)

Author

Commented:
Thanks harfang. all is well.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.