Click here to Skip to main content
Licence CDDL
First Posted 21 Feb 2008
Views 18,686
Downloads 310
Bookmarked 18 times

Setting Crystal Report Margin at Runtime

By | 21 Feb 2008 | Article
This article discusses how you can create a dynamic Crystal Report and set its Margin at runtime.

Introduction

This article discusses how you can create a dynamic Crystal Report and set its Margin at runtime.

Using the Code

The below function fills dataset's table from the Northwind database, and at form load, it loads the report and sets its datasource.

//
// Any source code blocks look like this
 Private Sub FillDataTable()
        Dim strQuery As String
        strQuery = "select * from  [Current Product List] "
        Dim sqlConn As New SqlConnection("Data Source=.;_
	Initial Catalog=NorthWind;UID=sa;Password=lumensoft2003;")
        Dim da As New SqlDataAdapter(strQuery, sqlConn)
        Try
            da.Fill(objdsReport, "dtProduct")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        Finally
            sqlConn.Dispose()
            da.Dispose()
        End Try
    End Sub

// on form load

    Private Sub frmReport_Load(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles MyBase.Load
        RptViwer.Width = Me.Width
        RptViwer.Height = Me.Height
        Dim objDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        FillDataTable()
        objDoc.Load(My.Application.Info.DirectoryPath + "\rptProduct.rpt")
        ' as 1 inch equal to 1440 tups
        objDoc.PrintOptions.ApplyPageMargins_
	(New CrystalDecisions.Shared.PageMargins_
		(1 * 1440, 1 * 1440, 1 * 1440, 1 * 1440))
        objDoc.SetDataSource(objdsReport)
        RptViwer.ReportSource = objDoc
    End Sub

//

If you have any questions, please email me at mailto:altafamber@yahoo.com.

History

  • 22nd February, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)

About the Author

altafsagar



Pakistan Pakistan

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 22 Feb 2008
Article Copyright 2008 by altafsagar
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid