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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO USE CRYSTAL FROM VB6

Status
Not open for further replies.

peresr

Programmer
Feb 19, 2003
3
US
I have Crystal Reports 9 and VB 6. Both installed, but I can not see Crystal Reports on my Project Menu. However, I do have the option Add-Ins/Report Designer.
How can I either have it on my Project Menu or how can I call an external report from VB?

Thanks in advance,
Rui
 
I don't know how helpful this may be..all I know is it does use Crystal and vb5.0 to generate a report.
This may not even be all the necessary code - I just cut and pasted from a legacy program. I do know you need the map.rpt file to exist in a defined logical path.

=========================================

Private Sub PrintMap(cust As String)
Dim lcryRep As CRPEAuto.Report
Dim lcryDB As CRPEAuto.Database
Dim lcryTable As CRPEAuto.DatabaseTable
Dim lcryParam As CRPEAuto.DatabaseParameter
Dim lLine As Long
Dim strFile As String, strServ As String

On Error GoTo chkError

strFile = aoiCommon.aoiRptMap
Set lcryRep = icre.OpenReport(aoiCommon.aoiRptMap)
lLine = 1
Set lcryDB = lcryRep.Database()
lLine = 2
For Each lcryTable In lcryDB.Tables
lLine = 3
With lcryTable
strServ = .DllName & " " & .LogOnServerName & " " & .LogOnDatabaseName & " " & aoiCommon.aoiUser & " " & aoiCommon.aoiPassword
icre.LogOnServer .DllName, .LogOnServerName, .LogOnDatabaseName, aoiCommon.aoiUser, aoiCommon.aoiPassword
End With
lLine = 4
Next
lLine = 5
For Each lcryParam In lcryDB.Parameters
lLine = 6
With lcryParam
Select Case .Name
Case "@crn"
.Value = RollAtt.Crn
Case "@map"
.Value = cust
End Select
End With
lLine = 7
Next
lLine = 8
lcryRep.Preview
lLine = 9
Exit Sub
chkError:
Select Case Err.Number
Case 20507
MsgBox CStr(Err.Number) & " - " & Err.Description & " - " & CStr(lLine) & " - " & strFile
Case Else
MsgBox CStr(Err.Number) & " - " & Err.Description & " - " & CStr(lLine)
End Select
End Sub

Private Sub m_reports_a_Click()
PrintMap ("A")
End Sub
-----------------------------------
then in aoiCommon.dll:
Private Sub PrintMap(aMap As String)
Dim lApp As CRPEAuto.Application
Dim lRep As CRPEAuto.Report
Dim lParm As DatabaseParameter
Dim ldb As Database
Dim ltbl As DatabaseTable

Set lApp = New CRPEAuto.Application

Set lRep = lApp.OpenReport(gReg.rptMap)
For Each lParm In lRep.Database.Parameters
Select Case lParm.Name
Case "@crn"
lParm.Value = isCrn
Case "@map"
lParm.Value = aMap
End Select
Next
Set ldb = lRep.Database
For Each ltbl In ldb.Tables
lApp.LogOnServer ltbl.DllName, gReg.Server, ltbl.LogOnDatabaseName, ltbl.LogOnUserID, gReg.Password
Next
lRep.PrintOut False
Set lRep = Nothing
Set lApp = Nothing
End Sub
 
If you have both VB6 and CR9 look in both Project References and Components and check the ones you want to use.

I set up my reports in CR and then import them to VB6
 
I have checked in both Components and references, but I can not find what I'm looking for.
With Crystal 7.0, I could go to my Project Menu, select Components, then select the Designers Tab and check Crystal Reports. By doing this I could then see 'Add Crystal Report' in my Project menu much like 'Add Report Data'. This way I could just select ' Add Crystal Report' and it would be added to my Project Explorer. If this is no longer the way to bring a report into VB, I don't know how else to import it.
Kim, you mention designing it in CR and importing to VB. How do you do that?

Thank you all who are helping me with this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top