Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb + crystal problem

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
ok whenever i try to generate a report from vb i get an error saying "Cannot open SQL server" i have no clue why its happening.

Private Sub cmdReport_Click()
CrystalReport1.ReportFileName = "test.rpt"
CrystalReport1.Action = 1
End Sub

Now the test.rpt only has 1 field in it, taken from an ODBC connection. When I preview the test.rpt in crystal it shows up just fine, but when I try to run it from vb i get that error. Someone plz help :)
 
When you run the report through VB you have to initiallize the ODBC connection in VB as well. Check out

Report.Database.Tables(1).SetLogOnInfo ServerName, DBName, UserName, Pwd

Check out SetLogOnInfo in Knowledge Base for the exact syntax to connect to SQL Server. My example above is for Oracle but I think it's similar for SQL Server. At any rate, you have to initialize the connection to the database for the report before you view it. Good luck.

CrystalVisualBOracle :)
 
ok i tried putting in

Report.Database.Tables(1).SetLogOnInfo "blah", "blah", "blah", "blah"


but now it says Object is missing

 
You didn't declare the report object.

Dim Report As New crptReport

In this case crptReport is the name I've given the report object in Visual Basic. This assumes that you have imported the report by clicking on Project/Add CrystalReport on the menu bar. You then click "existing report" and click on your report. This is the RDC method of creating a report in VB. First you create the report by importing it into the VB application and then you write the code to initialize the data connection for it.
 
ok I imported my crystal report into vb and put the following code into a cmd button but still no progress :

Dim Report As New CrystalReport1
CrystalReport1.ReportFileName = "test.rpt"
CrystalReport1.Database.Tables(0).SetLogOnInfo "test", "test", "test", "test"
CrystalReport1.ParameterFields(1) = "Module ; " & cmbModule.Text & " ; true "
CrystalReport1.Action = 1

The error says "Object doesnt support this property or method"

All I am trying to do is pass a parameter module to the report and view it





 
The following is example code found in one of my programs. This code is found form that holds the report viewer. When you imported the report to VB it should have set up the viewer form for you. That form's where it goes.



Dim Report As New crptCM_UR_AM

Private Sub Form_Load()

Screen.MousePointer = vbHourglass
Report.Database.Tables(1).SetLogOnInfo sDB1Server, sDB1Name, sDB1User, sDB1Pwd
CRViewer1.ReportSource = Report
CRViewer1.ViewReport

Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
 
yeah i got all that...now it says


Method 'Databse' of object 'IReport' failed


 
so this is what yours looks like????


Dim Report As New CrystalReport1

Private Sub Form_Load()
Screen.MousePointer = vbHourglass
Report.Database.Tables(0).SetLogOnInfo "test", "test", "test", "test"
Report.ReportFileName = "test.rpt"
Report.ParameterFields(1) = "Module ; " & cmbModule.Text & "; true "
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
End Sub
 
yeah thats what i got

it highlights CRViewer1.Top = 0
and says object required, i guess i am missing one again
 
First, check the name of your viewer in VB and verify that it's named CRViewer1.

Second, can you display your code?
 
Dim Report As New CrystalReport1

Private Sub Form_Load()
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
End Sub


That works just fine, but how do i edit it so i can pass parameters? i tried putting in

Report.ParameterFields(0) = "Module ; Test; true "

but it gave an error saying out of range
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top