on 05-30-2014 9:36 PM
Dang, I'm sooooooooooooo close! The attached VB code reads a file, modifies formulas, redirects tables to new ones, will evern PRINT the danged reports, but will NOT SHOW them? I'm converting from an old VS2008 version, where all that was needed was a CrystalReportViewer2.Refresh().
It absolutely connects to the database - I've printed out numerous reports, but it will NOT display them.
What am I missing?
Private Sub ShowReport()
Dim errstr As String = "No Error"
Try
Dim crtableLogoninfos As New CrystalDecisions.Shared.TableLogOnInfos()
Dim crtableLogoninfo As New CrystalDecisions.Shared.TableLogOnInfo()
'Dim crConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()
Dim CrTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim CrTable As CrystalDecisions.CrystalReports.Engine.Table
Dim i As Integer
errstr = "Loading Report"
crReportDocument.Load(ReportName)
'This code works for both user tables and stored
'procedures. Set the CrTables to the Tables collection
'of the report
CrTables = crReportDocument.Database.Tables
crReportDocument.SetDatabaseLogon("RPT", MyPassWord)
'change formula values
i = 1
While (i < MaxParms) And (Parms(i, 1) <> "")
errstr = "Setting Formula " & Parms(i, 1)
crReportDocument.DataDefinition.FormulaFields(Parms(i, 1)).Text = Parms(i, 2)
i = i + 1
End While
' now add login info to each table, see if needs to be changed
i = 1
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
'crtableLogoninfo.ConnectionInfo.ServerName = "IQORA"
crtableLogoninfo.ConnectionInfo.UserID = "RPT"
crtableLogoninfo.ConnectionInfo.Password = MyPassWord
CrTable.ApplyLogOnInfo(crtableLogoninfo)
MessageBox.Show(CrTable.Name & " - " & CrTable.Location & " - " & TableNames(i, 1))
If (i < MaxTables) Then
If (TableNames(i, 1) <> Nothing) Then
errstr = "Setting table " & CrTable.Location & " to " & TableNames(i, 1)
CrTable.Location = TableNames(i, 1)
End If
End If
'MessageBox.Show(CrTable.Name & " - " & CrTable.Location)
i = i + 1
Next
errstr = "Display"
'Set the viewer to the report object to be previewed.
'MessageBox.Show(crReportDocument.FileName)
CrystalReportViewer2.ReportSource = crReportDocument '"R:\Rpt60\IMC_Templatex.rpt"
'CrystalReportViewer2.PrintReport()
CrystalReportViewer2.Refresh()
CrystalReportViewer2.RefreshReport()
Catch E As Exception
' Let the user know what went wrong.
MessageBox.Show("Report error: " & errstr & E.Message)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Readparms()
ShowReport()
End Sub
Do I have to do anything WITH the CrystalViewer control? I can access ANY part of it, but it won't display! Should I be attaching it to the form somehow? It's weird that the parameter input form becomes visible after the .RefreshReport() call, but the parent itself isn't EVER visible.
Also, all of this is BEFORE the form itself is visible, if that turns on any lightbulbs. Like I said, this worked as-written in VS2008, I don't know if VS has changed, or Crystal.
Another three hours gone on a Sunday afternoon...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, good catch. I use C# so forgot to look for " ' " to see it's commented out.
Yes, you need the form. So to make this complete create a new VB Form app. Project will open up on the form page, open Tools and add the CR Viewer:
Check the Frame, must be full version and not client also.
Add a button and then drag and drop the Viewer onto the form:
Now in code under the Button1 click add my 3 lines of code and you should see the report. Use a saved data report to start with so it needs no prompts or DB connection info...
Don
Well, there's what's not happening.
I have to manually add the CrystalViewer control - it show up under General.
Then,when I add it, it shows up on the bottom of the screen, rather than on the form! So I never actually SEE the control as you have displayed it.
I've installed the executable three times, just uninstalled and reinstalled VS2013, thinking maybe that might fix it... I expected something like your screen shot - it's obvously THERE, but it's INVISIBLE.
razznfrazzn
Mine doesn't show up there, but where it DOES show up, it looks correct. I think the problem is that it DOESN'T show up there, I have to add it, when I thought the "install" program was supposed to put them there.
I'm downloading VS2012 to see if that works. I don't NEED 2013, it was just the latest/greatest.
Hi Bill,
Are you using VS Express? We don't support it, actually it's Microsoft that doesn't support plug-ins in ANY Express versions.
CRforVs SP 9 is the only one that supports VS 2013.
In VS 2013 it should be the same:
Uninstall Cr for VS once you get VS 2012 installed and then install it again so it integrates into Visual Studio.
I'm attaching my test app also, use any report with saved data to open. Unzip it and then rename the file from *.txt to *.zip and unzip the project.
Don
Well, I uninstalled VS1013, then re-installed, then RE-INSTALLED the SAP "install" program (13.09...), and now they show up, and display. The fact that they weren't showing up where they should have been was the key.
Thanks for all of your patience - I must say that SAP has improved 1,000,000% over the years. I'm actually at Sapphire right now, looking at implementation partners for SAP on Hana. This experience with you has certainly made me think we are making the right decision.
Thanks again!
I'm not a VB programmer (I do C# and Java), but I think the problem is this line:
CrystalReportViewer2.ReportSource = crReportDocument '"R:\Rpt60\IMC_Templatex.rpt"
You've updated everything in crReportDocument, so I don't think you need the reference to '"R:\Rpt60\IMC_Templatex.rpt".
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are correct Dell,
Bill, what youa re doing is assigning the report object twice:
crReportDocument.Load(ReportName)
Except this does not load the report into a report object.
Then your CrystalReportViewer2.ReportSource = crReportDocument '"R:\Rpt60\IMC_Templatex.rpt"
loads the report again so it completely ignores what you just set in code.
Here's the basic "one liner" Ludek is famous for:
Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
rpt.Load("c:\reports\world sales report.rpt")
CrystalReportViewer1.ReportSource = rpt
Thanks
Don
THanks, but the '"R:\Rpt60\IMC_Templatex.rpt" is actually
' "R:\Rpt60\IMC_Templatex.rpt",
which is commented out in VB. I tried to load this simple, nearly blank report, just to see if I could get SOMETHING to show up!
SO, still have the same problem.
Thanks for the response, though. I was hoping there was something beyond "Refresh", which worked perfectly in VS2008, but not now.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.