Rikol
asked on
Calling a crystal report with a parameter field
I am using VB 6 to create an application that opens a crystal report that has a parameter field called OrderNum. I have two forms, the starting form has a text field and two command buttons. I place the value of the text field in a public variable so that I can pass it to the crystal reports form. Here is the code for the starting form:
Private Sub cmdClose_Click()
End
End Sub
Private Sub cmdView_Click()
OrderN = txtOrderNum.Text
frmReportView.Show vbModal
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set CrxSubreport = Nothing
Set CrxReport = Nothing
Set crxApplication = Nothing
End Sub
I based this heavily from the example project they offer from the Crystal Reports website, here is the second form's code:
Private Sub cmdExit_Click()
frmReportView.Hide
Form1.Show
End Sub
Private Sub Form_Load()
Dim OrderNM As Integer
OrderNM = OrderN
Screen.MousePointer = vbHourglass
Set CrxReport = crxApplication.OpenReport( App.Path & "\Order-Detail.rpt")
CrxReport.DiscardSavedData
CrxReport.ParameterFields. GetItemByN ame("@Orde rNum").Add CurrentVal ue (OrderN)
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
frmReportView.WindowState = vbMaximized
CRViewer1.Zoom 100
Screen.MousePointer = vbDefault
End Sub
Now, no matter what I seem to do to get it to work I'm getting errors on this line of code:
CrxReport.ParameterFields. GetItemByN ame("@Orde rNum").Add CurrentVal ue (OrderN)
VB highlights .GetItemByName and says method or data member not found. Any help would be greatly appreciated. I'm using CR 8.0
Timmy
Private Sub cmdClose_Click()
End
End Sub
Private Sub cmdView_Click()
OrderN = txtOrderNum.Text
frmReportView.Show vbModal
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set CrxSubreport = Nothing
Set CrxReport = Nothing
Set crxApplication = Nothing
End Sub
I based this heavily from the example project they offer from the Crystal Reports website, here is the second form's code:
Private Sub cmdExit_Click()
frmReportView.Hide
Form1.Show
End Sub
Private Sub Form_Load()
Dim OrderNM As Integer
OrderNM = OrderN
Screen.MousePointer = vbHourglass
Set CrxReport = crxApplication.OpenReport(
CrxReport.DiscardSavedData
CrxReport.ParameterFields.
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
frmReportView.WindowState = vbMaximized
CRViewer1.Zoom 100
Screen.MousePointer = vbDefault
End Sub
Now, no matter what I seem to do to get it to work I'm getting errors on this line of code:
CrxReport.ParameterFields.
VB highlights .GetItemByName and says method or data member not found. Any help would be greatly appreciated. I'm using CR 8.0
Timmy
use CrxReport.ReportSelectionF ormula = "OrderNum=" & OrderN instead of using Parameters..
then
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
then
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
ASKER
Private Sub cmdExit_Click()
frmReportView.Hide
Form1.Show
End Sub
Private Sub Form_Load()
Dim OrderNM As Integer
Dim APath As String
OrderNM = OrderN
Screen.MousePointer = vbHourglass
Set CrxReport = crxApplication.OpenReport( App.Path & "\Order-Detail.rpt")
CrxReport.DiscardSavedData
'CrxReport.ParameterField. GetItemByN ame("Order Num").AddC urrentValu e (OrderNM)
CrxReport.ReportSelectionF ormula = "OrderNum=" & OrderN
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
frmReportView.WindowState = vbMaximized
CRViewer1.Zoom 100
Screen.MousePointer = vbDefault
End Sub
With the code like that I get an error on the line I added.
My module looks like this:
Option Explicit
Global crxApplication As New CRAXDRT.Application
Global CrxReport As CRAXDRT.Report
Public OrderN As Integer
frmReportView.Hide
Form1.Show
End Sub
Private Sub Form_Load()
Dim OrderNM As Integer
Dim APath As String
OrderNM = OrderN
Screen.MousePointer = vbHourglass
Set CrxReport = crxApplication.OpenReport(
CrxReport.DiscardSavedData
'CrxReport.ParameterField.
CrxReport.ReportSelectionF
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
frmReportView.WindowState = vbMaximized
CRViewer1.Zoom 100
Screen.MousePointer = vbDefault
End Sub
With the code like that I get an error on the line I added.
My module looks like this:
Option Explicit
Global crxApplication As New CRAXDRT.Application
Global CrxReport As CRAXDRT.Report
Public OrderN As Integer
ASKER
Error is Object does not support this property or method.
Try
CrxReport.RecordSelectionF ormula = "{Table.OrderNum}=" & OrderN
Change {Table.OrderNum} to the appropriate table and field name.
mlmcc
CrxReport.RecordSelectionF
Change {Table.OrderNum} to the appropriate table and field name.
mlmcc
If you wish to go back to the parameter method
CrxReport.ParameterFields. GetItemByN ame("{?Ord erNum}").A ddCurrentV alue (OrderN)
The name includes the { } and the ?
mlmcc
CrxReport.ParameterFields.
The name includes the { } and the ?
mlmcc
ASKER
Tried both. Same error. Hmmm....do you think it has anything to do with the fact that I'm using an ODBC driver to pull the data?
Timmy
Timmy
ASKER
Hmmm..new error. Took out the ? and now getting type mismatch. Will keep trying.
Timmy
Timmy
Do you have the developer edition of Crystal 8.0?
Have you installed the latest hotfix?
mlmcc
Have you installed the latest hotfix?
mlmcc
ASKER
Pretty sure it is not developers edition, it came bundled with a DB software that we've got. I'll get the latest hotfix though.
Timmy
Timmy
ASKER
NM. Can't get any hotfixes. Since it is an OEM version it's not compatable with the hotfixes from Seagate. I'll be downloading an updated version of the software this afternoon that will bump my CR up to 8.5. So maybe that will clear this up.
Timmy
Timmy
ASKER
Meant to update the points. :)
ASKER
Ok, CR now at 8.5. Now getting Invalid name and it points to this line
CrxReport.ParameterFields. GetItemByN ame("{?Ord erNum}").A ddCurrentV alue (OrderNM)
I've tried it without the ? and without the {} marks. Still getting the same error.
Timmy
CrxReport.ParameterFields.
I've tried it without the ? and without the {} marks. Still getting the same error.
Timmy
ASKER
After fiddling with it and commenting that line out and adding this one :
CrxReport.ParameterFields( 1).Value = OrderNM
I now get an object required error. But I know that I have that parameter field set up. I've checked the report 3 times now.
Timmy
CrxReport.ParameterFields(
I now get an object required error. But I know that I have that parameter field set up. I've checked the report 3 times now.
Timmy
Hi... Rikol... maybe this would help.
This is your code from your first message above.....
Private Sub Form_Load()
Dim OrderNM As Integer
OrderNM = OrderN
Screen.MousePointer = vbHourglass
Set CrxReport = crxApplication.OpenReport( App.Path & "\Order-Detail.rpt")
CrxReport.DiscardSavedData
'========================= ========== ========== ========== ===
' This was your old code
' CrxReport.ParameterFields. GetItemByN ame("@Orde rNum").Add CurrentVal ue (OrderN)
'========================= ========== ========== ========== ===
' change it with the following....
crxReport.ParameterFields( 1).AddCurr entValue (OrderN)
' The number represents the parameter field's order in your crystal report.
' If there are many parameter fields in your report, just place its order accordingly...
' e.g. crxReport.ParameterFields( 1) , crxReport.ParameterFields( 2),. ... etc.
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
frmReportView.WindowState = vbMaximized
CRViewer1.Zoom 100
Screen.MousePointer = vbDefault
End Sub
This is your code from your first message above.....
Private Sub Form_Load()
Dim OrderNM As Integer
OrderNM = OrderN
Screen.MousePointer = vbHourglass
Set CrxReport = crxApplication.OpenReport(
CrxReport.DiscardSavedData
'=========================
' This was your old code
' CrxReport.ParameterFields.
'=========================
' change it with the following....
crxReport.ParameterFields(
' The number represents the parameter field's order in your crystal report.
' If there are many parameter fields in your report, just place its order accordingly...
' e.g. crxReport.ParameterFields(
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
frmReportView.WindowState = vbMaximized
CRViewer1.Zoom 100
Screen.MousePointer = vbDefault
End Sub
ASKER
No errors when I switch it to that, but coming up with a blank report again.
Keeps doing that, I've got a feeling that it's not connecting the ODBC to the server. That's the only way I know to put it.
Timmy
Keeps doing that, I've got a feeling that it's not connecting the ODBC to the server. That's the only way I know to put it.
Timmy
ASKER
This is my code as it now stands. I have commented out various stuff that I've been trying to get it to work with. I'm still working on getting the log on server line correct.
Hehe. For security purposes I've replaced my username with Myusr and my password with Mypswrd. Just a silly little precaution. :)
Private Sub Form_Load()
Dim OrderNM As String
Dim APath As String
Dim FieldName As String
Dim CheckData As String
OrderNM = Str(OrderN)
APath = "C:\Custom Reports\VB Stuff\Order-Detail.rpt"
Screen.MousePointer = vbHourglass
Set CrxReport = crxApplication.OpenReport( APath)
CrxReport.DiscardSavedData
CrxReport.EnableParameterP rompting = False
FieldName = CrxReport.ParameterFields( 1).Name
'crxReport.Database.LogOnS erver "invenodbc.dll", "PROGRESS", "INVEN", "myuser", "mypswrd"
'CrxReport.ParameterFields .GetItemBy Name("Orde rNum").Add CurrentVal ue (OrderNM)
'CrxReport.ParameterFields (1).Value = OrderNM
CrxReport.ParameterFields( 1).AddCurr entValue (OrderNM)
CheckData = CrxReport.ParameterFields( 1).Value
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
frmReportView.WindowState = vbMaximized
CRViewer1.Zoom 100
Screen.MousePointer = vbDefault
End Sub
Hehe. For security purposes I've replaced my username with Myusr and my password with Mypswrd. Just a silly little precaution. :)
Private Sub Form_Load()
Dim OrderNM As String
Dim APath As String
Dim FieldName As String
Dim CheckData As String
OrderNM = Str(OrderN)
APath = "C:\Custom Reports\VB Stuff\Order-Detail.rpt"
Screen.MousePointer = vbHourglass
Set CrxReport = crxApplication.OpenReport(
CrxReport.DiscardSavedData
CrxReport.EnableParameterP
FieldName = CrxReport.ParameterFields(
'crxReport.Database.LogOnS
'CrxReport.ParameterFields
'CrxReport.ParameterFields
CrxReport.ParameterFields(
CheckData = CrxReport.ParameterFields(
CRViewer1.ReportSource = CrxReport
CRViewer1.ViewReport
frmReportView.WindowState = vbMaximized
CRViewer1.Zoom 100
Screen.MousePointer = vbDefault
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've tried that out and still no go. Just using the parameter prompt from CR to get the data. Will try again another time to pass data to parameter fields from VB. Thanks for all the help though. :)
Timmy
Timmy
Try this ...
Public Function CrystalExport(sDocPath As String, sFilePath As String, lUTBDAT As Long, sPNR As String, sEmailAdd As String, sBatch As String) As Boolean
Dim lCount As Long
Dim lMax As Long
Dim sSelectString As String
Dim c_Mail As cMail
Dim fs As FileSystemObject
Dim strFile As String
On Error GoTo Err
'add the reference to Crystal Report Viewer Control and the Crystal report 8 ActiveX Designer Run Time Lib
If IsObject(crRpt) Then
Set crRpt = Nothing
End If
Set crApp = New CRAXDRT.Application
Set crRpt = crApp.OpenReport(sDocPath, 1)
With crRpt
' Logon do the Log on
.Database.LogOnServer "pdsodbc.dll", "RESPONS", "RESPONS", "SYSADM", "sysadm"
lCount = 1
lMax = .Database.Tables.Count
'For some stupid reason, you have to log on all the tables
Do While lCount <= lMax
.Database.Tables(lCount).S etLogOnInf o "RESPONS", "RESPONS", "SYSADM", "SYSADM"
lCount = lCount + 1
Loop
'Get rid of saved data
.DiscardSavedData
End With
With crRpt
'Do the parameters
'We will only check for these 2 parameters
For lCount = 1 To crRpt.ParameterFields.Coun t
If UCase(.ParameterFields(lCo unt).Name) = "{?DATE}" Then
.ParameterFields(lCount).E nableNullV alue = True
.ParameterFields(lCount).A ddCurrentV alue (CLng(lUTBDAT))
ElseIf UCase(.ParameterFields(lCo unt).Name) = "{?EMP NO}" Then
.ParameterFields(lCount).E nableNullV alue = True
.ParameterFields(lCount).A ddCurrentV alue sPNR
Else
End If
Next lCount
'Do the Export to HTML
.ExportOptions.FormatType = crEFTHTML40
.ExportOptions.Destination Type = crEDTDiskFile
.ExportOptions.DiskFileNam e = "c:\test.htm"
.ExportOptions.HTMLFileNam e = "c:\test.htm"
.Export False
End With
CrystalExport = True
Exit Function
Err:
MsgBox Err.Description, vbInformation
CrystalExport = False
End Function
Hope it works
VX
Public Function CrystalExport(sDocPath As String, sFilePath As String, lUTBDAT As Long, sPNR As String, sEmailAdd As String, sBatch As String) As Boolean
Dim lCount As Long
Dim lMax As Long
Dim sSelectString As String
Dim c_Mail As cMail
Dim fs As FileSystemObject
Dim strFile As String
On Error GoTo Err
'add the reference to Crystal Report Viewer Control and the Crystal report 8 ActiveX Designer Run Time Lib
If IsObject(crRpt) Then
Set crRpt = Nothing
End If
Set crApp = New CRAXDRT.Application
Set crRpt = crApp.OpenReport(sDocPath,
With crRpt
' Logon do the Log on
.Database.LogOnServer "pdsodbc.dll", "RESPONS", "RESPONS", "SYSADM", "sysadm"
lCount = 1
lMax = .Database.Tables.Count
'For some stupid reason, you have to log on all the tables
Do While lCount <= lMax
.Database.Tables(lCount).S
lCount = lCount + 1
Loop
'Get rid of saved data
.DiscardSavedData
End With
With crRpt
'Do the parameters
'We will only check for these 2 parameters
For lCount = 1 To crRpt.ParameterFields.Coun
If UCase(.ParameterFields(lCo
.ParameterFields(lCount).E
.ParameterFields(lCount).A
ElseIf UCase(.ParameterFields(lCo
.ParameterFields(lCount).E
.ParameterFields(lCount).A
Else
End If
Next lCount
'Do the Export to HTML
.ExportOptions.FormatType = crEFTHTML40
.ExportOptions.Destination
.ExportOptions.DiskFileNam
.ExportOptions.HTMLFileNam
.Export False
End With
CrystalExport = True
Exit Function
Err:
MsgBox Err.Description, vbInformation
CrystalExport = False
End Function
Hope it works
VX
ASKER
CrxReport.ParameterFields.
Timmy