Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

How to refresh the data of a report using the 'Refresh' button

Greetings

I'm not sure what code is needed within the 'CRViewer1_RefreshButtonClicked' event to display changes in the data.  In other words, I've tried a couple different approaches but when the refresh button is clicked, the data is no different.  Here is what I've tried so far:

----------------------------------------------
Private Sub CRViewer1_RefreshButtonClicked(UseDefault As Boolean)

Form2.CRViewer1.Refresh

End Sub
----------------------------------------------

Private Sub CRViewer1_RefreshButtonClicked(UseDefault As Boolean)

 Call CreateRecordsets
 Report.Database.Tables.Item(1).SetDataSource ADOTest, 3
 CRViewer1.ReportSource = Report
 CRViewer1.ViewReport

End Sub    
----------------------------------------------

Neither of these two approaches worked, what am I missing?  Thanks.
0
John500
Asked:
John500
  • 6
  • 6
  • 2
1 Solution
 
DRRYAN3Commented:
Why not just let Crystal refresh the report using its default action?

private sub CRViewer1_RefreshButtonClicked(UseDefault as Boolean)
  UseDefault = true
end sub

Unless you need to insert some action into the refresh process, this should suffice.

DRRYAN3
0
 
John500Author Commented:
DRRYAN3,

Now that you mention it, I do already have some 'actions' within which ensure the report has the correct colors displayed.  Here's what I have and although it already has 'UseDefault = true', it doesn't work:

Private Sub CRViewer1_RefreshButtonClicked(UseDefault As Boolean)

    UseDefault = True
   
    Dim crSections As CRAXDRT.Sections
    Dim crSection As CRAXDRT.Section
    Dim crTextObject As Object
    Dim crReportObject As Object
   
    'Unload Form2
 
    Form2.Visible = True
    Form2.Enabled = False
    Form1.Command1.Visible = False
    Form1.Command3.Visible = True
    Form1.Visible = True
   
    Set crSections = Report.Sections
   
         For Each crSection In crSections
         
             crSection.BackColor = &HC0C0C0
             Report.Section1.BackColor = &H800000
             Report.Text1.TextColor = vbWhite
   
    Next crSection
   
   
End Sub

What do you think is wrong??
0
 
DRRYAN3Commented:
What's not working?   The color setup, or the data refresh?
0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
John500Author Commented:
The data refresh is definitely not working.  The color setup works fine.  I needed the code to adjust the color because during a print job, the colors are turned to black and white.  If the refresh button is clicked after a print job, the colors are black and white rather than blue...

0
 
DRRYAN3Commented:
Does the data refresh work if you strip out the color setup code?  I don't see any problem with what you have there, but CR can be quirky sometimes.
0
 
mlmccCommented:
listening
0
 
John500Author Commented:
DRRYAN3/mlmcc,

>> Does the data refresh work if you strip out the color setup code?

The answer to this question is no.  I got rid of the code related to the color and had to keep the following lines in order for the report to run right?  Any ideas at this point?  I'm wondering if the switch between forms causes the the refresh action to be cancelled because it really just displays the previous data, yes/no??  Thanks


Private Sub CRViewer1_RefreshButtonClicked(UseDefault As Boolean)

    Form2.Visible = True
    Form2.Enabled = False
    Form1.Command1.Visible = False
    Form1.Command3.Visible = True
    Form1.Visible = True

    UseDefault = True
   
End Sub
0
 
DRRYAN3Commented:
Why are you switching forms?  If you have the viewer control on one of the forms, that is the form which has to stay active in order for the refresh to occur.  As far as I know, you cannot have the same report instance active on two forms simultaneously.
0
 
John500Author Commented:
DRRYAN3,

The reason is this, Form1 handles parameter passing.  Thus, the user must first choose the appropriate value to proceed with the main the main query.  After Form1 obtains the parameter, it passes it to Form2 to reissue the query.

In regard to the 'same report instance' on two forms, that's not what's happening.  In other words, Form1 doesn't have a CRViewer, only a box with a drop down list for the user to choose a parameter.  The report does have a module and within the module a global declaration is made that looks like this:

Public Report As New CrystalReport1

So what do you think?
0
 
DRRYAN3Commented:
We may be discussing two different things here.

If you are changing the parameters which are driving the report, then this is best accomplished by closing the first instance of the report and starting over with a new instance of the report object and passing the new parameters to the new object.  The Refresh command of the report object is not designed to handle this type of action.

On the other hand, if you have had the report open for a while and now want to incorporate any new records into the report which have been added to the database (without changing the parameters), this is what the refresh command was designed to do.

Which scenario do you fall into?
0
 
John500Author Commented:
The parameters which are offered to the user do not change.  Therefore, the 2nd scenario is true.  However, I tend to think that even if the 1st scenario was true, the 'refresh' could still be accomplished with the appropriate code.

In any case, don't you think a command like

Form2.CRViewer1.Refresh

.... would do the trick??

Actually, this is exactly what I have in the Form1 code and that code was given to me (or suggested) by the CR tech people way back (2 years) when I first made the report.

What do you think?
0
 
DRRYAN3Commented:
You are correct - the refresh method of the viewer is supposed to reload the report from its original source.

In which form is your event handler for the refresh clicked?  I generally put it in the code for the form containing the viewer.  Once the viewer has been displayed in form2 it shouldn't be necessary to activate/deactivate form1 until the user has closed the viewer.

0
 
John500Author Commented:
DRRYAN3,

Form2 holds the code for the refreshed clicked event, which is the form containing the viewer.  When you say it shouldn't be necessary to activate/deactivate Form1 until the user has closed the viewer, I have to say my code doesn't work that way.  

That is, the viewer is not closed when the refresh button is selected.  What happens is, Form2 (the viewer) is disabled and then hidden because Form1 is displayed in order to offer the user a choice of input parameters, once the user chooses a parameter, Form2 is enabled and displayed.

However, not all of my reports require an input parameter and therefore, only contain one fomr (Form1) which contains the viewer.  The refresh button doesn't work for these reports either.........
0
 
mlmccCommented:
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now