John500
asked on
How to refresh the data of a report using the 'Refresh' button
Greetings
I'm not sure what code is needed within the 'CRViewer1_RefreshButtonCl icked' 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_RefreshButtonCli cked(UseDe fault As Boolean)
Form2.CRViewer1.Refresh
End Sub
-------------------------- ---------- ----------
Private Sub CRViewer1_RefreshButtonCli cked(UseDe fault As Boolean)
Call CreateRecordsets
Report.Database.Tables.Ite m(1).SetDa taSource ADOTest, 3
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
End Sub
-------------------------- ---------- ----------
Neither of these two approaches worked, what am I missing? Thanks.
I'm not sure what code is needed within the 'CRViewer1_RefreshButtonCl
--------------------------
Private Sub CRViewer1_RefreshButtonCli
Form2.CRViewer1.Refresh
End Sub
--------------------------
Private Sub CRViewer1_RefreshButtonCli
Call CreateRecordsets
Report.Database.Tables.Ite
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
End Sub
--------------------------
Neither of these two approaches worked, what am I missing? Thanks.
ASKER
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_RefreshButtonCli cked(UseDe fault 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??
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_RefreshButtonCli
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??
What's not working? The color setup, or the data refresh?
ASKER
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...
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.
listening
ASKER
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_RefreshButtonCli cked(UseDe fault As Boolean)
Form2.Visible = True
Form2.Enabled = False
Form1.Command1.Visible = False
Form1.Command3.Visible = True
Form1.Visible = True
UseDefault = True
End Sub
>> 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_RefreshButtonCli
Form2.Visible = True
Form2.Enabled = False
Form1.Command1.Visible = False
Form1.Command3.Visible = True
Form1.Visible = True
UseDefault = True
End Sub
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.
ASKER
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?
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?
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?
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?
ASKER
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?
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?
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.
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.
ASKER
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.........
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.........
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
private sub CRViewer1_RefreshButtonCli
UseDefault = true
end sub
Unless you need to insert some action into the refresh process, this should suffice.
DRRYAN3