hiadan_dan
Jul 24th, 2008, 04:03 AM
Whut I try to do here I trying to get information based on range of date in order to display on CR 10. The thing is how am i going to declare in selection formula?Below is my code..plz anyone help me...
Dim crApp As CRAXDRT.Application
Dim Report As CRAXDRT.Report
Dim strSelectionfrm As String
Set crApp = New CRAXDRT.Application
Set Report = crApp.OpenReport("C:\Program Files\Microsoft Visual Studio\VB98\Projects\LeaveApp\LeaveForm4.rpt")
Report.Database.Tables(1).SetLogOnInfo "SQL", "tebrauteguh", "sa", "sa"
strSelectionfrm = "{tblLeaveApp.EmpNo}='" & ndEmpNoView & "'and {tblLeaveApp.Ldate}- {tblLeaveApp.Fdate}='" & ndDays & "'" '-->I try to select from range
Report.RecordSelectionFormula = strSelectionfrm
Report.DiscardSavedData
Form9.CRV.ReportSource = Report
Form9.CRV.ViewReport
Form9.Show
Me.Hide
Me.MousePointer = vbNormal
Besoup
Jul 24th, 2008, 10:17 AM
Not sure but you can try
strSelectionfrm = "{tblLeaveApp.EmpNo}='" & ndEmpNoView & "'and DateDiff({tblLeaveApp.Ldate}, {tblLeaveApp.Fdate})='" & ndDays & "'" '-->I try to select from range
TDQWERTY
Dec 2nd, 2011, 09:15 AM
Here (http://www.kenhamady.com/form07.shtml)you have a few examples of ranges, i would advise you to use parameter fields, they aren't easer to use.
Although when i print reports, i filter the sql data before printing the report so it will take few time to print, specially when you have big amounts of data:
Commented are the lines that allow to load the report with specific sql query and uncommented is how to use parameter fields.
This was taken from a current development. You might want to take a look to the idea and not specifically to the code
Public Sub printReportAssistencia(Optional ByVal NomeCliente As String = "", Optional ByVal NumHorasContrato As String = "", Optional ByVal NumAssistencia As Double = 0)
Dim objRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
'Dim cnn As SqlConnection
'Dim sql As String
'Dim ds As New DataSet
Dim __printPreview As New frmPrintPreview
'cnn = New SqlConnection(GetConnectionString)
'cnn.Open()
'condicoesSQL = IIf(condicoesSQL = String.Empty, " WHERE 1=1", condicoesSQL)
'condicoesSQL = " WHERE " & condicoesSQL
'sql = "select * from Imoveis" & condicoesSQL
'Dim dscmd As New SqlDataAdapter(sql, cnn)
objRpt.Load(GetAppPath & "Reports\assistencia.rpt")
objRpt.DataSourceConnections.Item(0).SetLogon(__sqlUser, __sqlPass)
objRpt.DataSourceConnections.Item(0).SetConnection(__SQLserverName, __sqlDatabase, False)
objRpt.SetDatabaseLogon(__sqlUser, __sqlPass, __SQLserverName, __sqlDatabase)
'dscmd.Fill(ds)
'objRpt.SetDataSource(ds.Tables(0))
'objRpt.SetParameterValue("NumHorasContrato", """Número de horas do contrato aqui""")
objRpt.DataDefinition.FormulaFields("NomeCliente").Text = NomeCliente
objRpt.DataDefinition.FormulaFields("NumHorasContrato").Text = NumHorasContrato
objRpt.DataDefinition.FormulaFields("NumAssistencia").Text = NumAssistencia
__printPreview.MdiParent = MAIN_MDI_FORM
__printPreview.CrystalReportViewer1.ReportSource = objRpt
__printPreview.CrystalReportViewer1.Refresh()
'CType(__printPreview.CrystalReportViewer1.Controls(4), ToolStrip).Items(CType(__printPreview.CrystalReportViewer1.Controls(4), ToolStrip).Items.Count - 1).BackgroundImage = My.Resources.ResLogos.logo
__printPreview.Show()
End Sub