SlideShare a Scribd company logo
1 of 35
Download to read offline
Tutorial on How to
Load images in Crystal Reports dynamically
Using Visual Basic 6 and Access 2000
By Aeric Poon
Introduction
This tutorial will show you how to create a Visual Basic 6 project which will generate a report using Seagate Crystal
Reports 8.5 Developer Edition. You will save the path of the image files in a MS Access database where it is protected
by password. This project will use an external Crystal Report file and will be previewed using Crystal Viewer control.
Get Ready
In this tutorial, I will use some small images I get from forwarded email. I created a folder name Tutorial where all the
files will be store inside this folder. I also created some images with different type like bmp, jpg, gif, png and tif which
will be stored inside a folder name Cake.
Contents
Step 1 Create a Database file using MS Access
Step 2 Create a Crystal Reports file
Step 3 Create a Visual Basic Project
Step 1
Create a Database file using MS Access
Run MS Access to create a blank database. Create a folder name Data. In the File New Database dialogue box, type
the name dbCake (dbCake.mdb) and click on Create to save this file inside folder Data.
You have now created a database file.
Click on Create table in Design view. Click the Design button to create a new table.
Create the following fields in the new table:
CakeID (Text), CakeName (Text), FileName (Text)
Set focus at CakeID and then click the Primary Key button to make this field as Primary Key.
Close the Table window or click Save button. Save this table name as Cake.
Right click and Open table Cake.
Insert some records in the table Cake. Save and Close the table Cake.
Set a Database Password. For this tutorial, I set the password as yuMMy20.
Click OK and Close this file. Now you have a database file ready.
Step 2
Create a Crystal Reports file
Run Crystal Reports 8.5 Developer. Click on As a Blank Report radio button in the Crystal Report Gallery dialogue
box and click OK.
You will see a Data Explorer dialogue box. Click on the plus sign of More Data Sources.
Click on the plus sign of Active Data and then click on Active Data (ADO).
You will see a Select Data Source dialogue box. Choose MS Access Database from the dropdown list and click OK.
Browse for the Data folder where we store the database file, click dbCake.mdb and then click OK.
A Login dialogue will pop out. Enter yuMMy20 for the password and click OK.
Then you will be asking to choose the database again. Click on dbCake.mdb and click OK.
You will be brought back to Data Explorer and you will notice there is an icon for ado. We have successfully
connected the Report with the database. Click on Add button.
You will see a Select Recordset dialogue box.
Click on SQL radio button so you can change the query if you want to do so. This is useful if you have WHERE
keyword in the SQL statement to filter the records.
After you have modified your SQL query, click on OK. Now you can see there is a green tick at the ado icon in Data
Explorer. Click Close.
Now you will see a Field Explorer dialogue box. Click on the plus sign next to Database Fields:.
Click on the plus sign next to ado and you will see all the fields generated from the SQL query.
Drag and drop or click on the field and press Enter to insert the field to the report.
Add more fields to the report in Details section and resize the width as your preference.
Click on Insert Picture icon to insert image file. If you couldn t find the tool, click on menu View, Toolbars and
check the Supplementary Tools checkbox.
Browse for an image to insert. Resize it to fit your report. Format the appearance of the picture object like adding
borders.
You can modify the report design by adding lines, box, labels for company title and address or put a logo.
Click on Preview tab to show how the report will look like. In this stage, the picture is fixed.
Click on menu File and uncheck the Save Data with Report option.
Save this report with filename Catalogue (Catalogue.rpt) inside folder Report.
Step 3
Create a Visual Basic Project
You have the database and report file ready. So, the final step is to create the front-end using MS Visual Basic 6.
Create a new Standard EXE by clicking Open.
Right click the Toolbar and click on Components
Scroll down to look for Crystal Report Viewer Control. Check the checkbox next to it.
Click on Designers tab. Check on Crystal Reports 8.5 and click OK.
Click on menu Project and click References
Look for Microsoft ActiveX Data Objects 2.8 Library (Latest version of ADO control). Check the checkbox next to it.
Add also the Crystal Reports 8.5 ActiveX Designer Run Time Library and click OK.
Right click the Project Explorer, click Add and then click on Crystal Reports 8.5
Click on the From an Existing Report radio button and click OK.
Browse for the report file we have designed just now and click Open.
On the Crystal Report Expert dialogue box, click No radio button for the upper option.
You can notice that Details section is named Section5 in bracket. You can change the name of the section if you like.
To hide the FileName field, right click the FileName field and click on Format .
On the Common tab, check the checkbox next to Suppress.
Hide the Report Header and Report Footer by right click the section separator and click on Suppress (No Drill-Down).
If you have made changes in the database table, right click the ado and click verify database.
You will be asked for the database password. Key in the password and click OK.
A Select Recordset dialogue box will appear. Click OK if the SQL is correct.
A message will pop up to inform you that the ado has changed. Click OK.
I have added a new field Price in the database table. Click OK to continue.
Now, click at the plus sign of ado and you can see the new field is added.
Drag and drop the new field and set HorAlignment to crLeftAlign.
Rename Picture1 as picCake and Field5 for FileName as adoFileName.
Right click inside any section, click on Report and click Save to Crystal reports File .
Browse for the report file and click Yes to replace it. Make a backup if you wish to do so.
Click OK to proceed.
Remove the report designer if you want as we are going to use the external report file.
Right click on the Project Explorer and click on Module.
Click Open to add the new Module.
Insert the following code and save the module as modCake.
Option Explicit
Public cn As ADODB.Connection
Public crx As New CRAXDRT.Application
Public Function OpenDatabase() As Boolean
On Error GoTo checkErr
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = "Data Source=" & App.Path & "DatadbCake.mdb"
cn.Properties("Jet OLEDB:Database Password") = "yuMMy20"
cn.Open
OpenDatabase = True
Exit Function
checkErr:
MsgBox Err.Description, vbExclamation, Err.Number
End Function
The code above is for connecting to the Access 2000 database with password protected using ADO. It is
recommended to encrypt the password for higher security. The Crystal Report Application is also set in this module as
a Public variable.
Click on Form1. Add a button name cmdPrint on Form1. Change the button caption to Print Catalogue.
Change Form1 BorderStyle as Fixed Single and caption or icon if you like.
Click View Code and insert the following code in Form1 and save it as frmPrint.
Option Explicit
Private Sub cmdPrint_Click()
frmReport.WindowState = 2
frmReport.Show
Unload Me
End Sub
Private Sub Form_Load()
If OpenDatabase = False Then
Unload Me
Exit Sub
End If
End Sub
The above code will connect to the database when the Form loads.
If the database failed to load, check the database path, filename and password.
If the application failed to start, it will quit.
The print button will open a report form which we are going to create later.
The report form will be open as a Maximized window.
Now add a new form. Click CRViewer to add a Crystal Report Viewer object on this form.
Add the following code and save the form as frmReport.
Option Explicit
Dim rpt As CRAXDRT.Report
Dim db As CRAXDRT.Database
Dim rs As New ADODB.Recordset
Dim WithEvents sect As CRAXDRT.Section
Private Sub Form_Load()
Screen.MousePointer = vbHourglass
Set rpt = crx.OpenReport(App.Path & "ReportCatalogue.rpt")
Set db = rpt.Database
Set sect = rpt.Sections("Section5")
rs.Open "SELECT * FROM Cake", cn, 1, 1
rpt.Database.SetDataSource rs, 3, 1
CRViewer1.ReportSource = rpt
CRViewer1.ViewReport
CRViewer1.Zoom 1
Screen.MousePointer = vbDefault
End Sub
Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
End Sub
Private Sub Form_Unload(Cancel As Integer)
cn.Close
End Sub
Private Sub sect_Format(ByVal pFormattingInfo As Object)
Dim bmp As StdPicture
On Error Resume Next
With sect.ReportObjects
Set .Item("picCake").FormattedPicture = LoadPicture(App.Path & "Cakeck99.gif") 'default
If .Item("adoFileName").Value <> "" Then
Set bmp = LoadPicture(App.Path & "Cake" & .Item("adoFileName").Value)
Set .Item("picCake").FormattedPicture = bmp
End If
End With
End Sub
Now we have finished all the coding. Click on Start button to execute the project.
Click on the Print Catalogue button.
The report preview will show up. Click the printer button if you want to print the report.
This is how the trick works. Happy Coding.
Please send me an email at aeric80 [at] gmail [dot] com if you found any mistakes in this document or you want to
suggest any improvement.

More Related Content

What's hot

Excel presentation data validation
Excel presentation   data validationExcel presentation   data validation
Excel presentation data validationNagamani Y R
 
Microsoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptxMicrosoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptxsamtakke1
 
Microsoft Access.ppt
Microsoft Access.pptMicrosoft Access.ppt
Microsoft Access.pptwondmhunegn
 
Open Office Impress : Lesson 08
Open Office Impress : Lesson 08Open Office Impress : Lesson 08
Open Office Impress : Lesson 08thinkict
 
State management
State managementState management
State managementteach4uin
 
Data validation - Excel
Data validation - ExcelData validation - Excel
Data validation - ExcelYi Chiao Cheng
 
MS Excel Pivot Table Reports & Charts
MS Excel Pivot Table Reports & ChartsMS Excel Pivot Table Reports & Charts
MS Excel Pivot Table Reports & Chartsdnbakhan
 
Learn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database FirstLearn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database FirstJibran Rasheed Khan
 
Front-end development introduction (HTML, CSS). Part 1
Front-end development introduction (HTML, CSS). Part 1Front-end development introduction (HTML, CSS). Part 1
Front-end development introduction (HTML, CSS). Part 1Oleksii Prohonnyi
 
Microsoft Word 2010
Microsoft Word 2010Microsoft Word 2010
Microsoft Word 2010home
 

What's hot (20)

Libre office calc
Libre office calcLibre office calc
Libre office calc
 
Excel presentation data validation
Excel presentation   data validationExcel presentation   data validation
Excel presentation data validation
 
Ms access
Ms accessMs access
Ms access
 
Ms access
Ms accessMs access
Ms access
 
Introduction to Tableau
Introduction to Tableau Introduction to Tableau
Introduction to Tableau
 
Microsoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptxMicrosoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptx
 
Microsoft Access.ppt
Microsoft Access.pptMicrosoft Access.ppt
Microsoft Access.ppt
 
HTML5 & CSS3
HTML5 & CSS3 HTML5 & CSS3
HTML5 & CSS3
 
How To Use Canva
How To Use CanvaHow To Use Canva
How To Use Canva
 
Open Office Impress : Lesson 08
Open Office Impress : Lesson 08Open Office Impress : Lesson 08
Open Office Impress : Lesson 08
 
001.general
001.general001.general
001.general
 
MS Access 2007 in ITT
MS Access 2007 in ITTMS Access 2007 in ITT
MS Access 2007 in ITT
 
State management
State managementState management
State management
 
Libre Office Calc Lesson 5: Working with Data
Libre Office Calc Lesson 5: Working with DataLibre Office Calc Lesson 5: Working with Data
Libre Office Calc Lesson 5: Working with Data
 
Data validation - Excel
Data validation - ExcelData validation - Excel
Data validation - Excel
 
MS Excel Pivot Table Reports & Charts
MS Excel Pivot Table Reports & ChartsMS Excel Pivot Table Reports & Charts
MS Excel Pivot Table Reports & Charts
 
Libre Office Writer Lesson 2
Libre Office Writer Lesson 2Libre Office Writer Lesson 2
Libre Office Writer Lesson 2
 
Learn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database FirstLearn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database First
 
Front-end development introduction (HTML, CSS). Part 1
Front-end development introduction (HTML, CSS). Part 1Front-end development introduction (HTML, CSS). Part 1
Front-end development introduction (HTML, CSS). Part 1
 
Microsoft Word 2010
Microsoft Word 2010Microsoft Word 2010
Microsoft Word 2010
 

Similar to Tutorial on how to load images in crystal reports dynamically using visual basic 6 and access 2000

OBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsOBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsDharmaraj Borse
 
Events Registration System Part 1
Events Registration System Part 1Events Registration System Part 1
Events Registration System Part 1Adolfo Nasol
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universitylhkslkdh89009
 
Create a basic performance point dashboard epc
Create a basic performance point dashboard   epcCreate a basic performance point dashboard   epc
Create a basic performance point dashboard epcEPC Group
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxkeilenettie
 
Dynamic Web Pages Ch 4 V1.0
Dynamic Web Pages Ch 4 V1.0Dynamic Web Pages Ch 4 V1.0
Dynamic Web Pages Ch 4 V1.0Cathie101
 
How to Download IDEA for Windows Based ComputersSelect the dow.docx
How to Download IDEA for Windows Based ComputersSelect the dow.docxHow to Download IDEA for Windows Based ComputersSelect the dow.docx
How to Download IDEA for Windows Based ComputersSelect the dow.docxwellesleyterresa
 
( 5 ) Office 2007 Create A Business Data Catolog
( 5 ) Office 2007   Create A Business Data Catolog( 5 ) Office 2007   Create A Business Data Catolog
( 5 ) Office 2007 Create A Business Data CatologLiquidHub
 
Database development connection steps
Database development connection stepsDatabase development connection steps
Database development connection stepsAravindharamanan S
 
Fr net programmermanual-en
Fr net programmermanual-enFr net programmermanual-en
Fr net programmermanual-enMorenita Batista
 
Creating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolCreating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolRavi Kumar Lanke
 
CIS 3100 - Database Design and ImplementationProducts on Sale Da.docx
CIS 3100 - Database Design and ImplementationProducts on Sale Da.docxCIS 3100 - Database Design and ImplementationProducts on Sale Da.docx
CIS 3100 - Database Design and ImplementationProducts on Sale Da.docxmccormicknadine86
 
XPages - The Ties That Bind
XPages - The Ties That BindXPages - The Ties That Bind
XPages - The Ties That BindMichael McGarel
 
- Database Design and ImplementationProducts on Sale Database fo.docx
- Database Design and ImplementationProducts on Sale Database fo.docx- Database Design and ImplementationProducts on Sale Database fo.docx
- Database Design and ImplementationProducts on Sale Database fo.docxgertrudebellgrove
 
A. Lab # BSBA BIS245A-7B. Lab 7 of 7 Database Navigation.docx
A. Lab #  BSBA BIS245A-7B. Lab 7 of 7  Database Navigation.docxA. Lab #  BSBA BIS245A-7B. Lab 7 of 7  Database Navigation.docx
A. Lab # BSBA BIS245A-7B. Lab 7 of 7 Database Navigation.docxransayo
 
Product Supplier59,58,8,2.50CIS 3100 - Database Desig.docx
Product Supplier59,58,8,2.50CIS 3100 - Database Desig.docxProduct Supplier59,58,8,2.50CIS 3100 - Database Desig.docx
Product Supplier59,58,8,2.50CIS 3100 - Database Desig.docxstilliegeorgiana
 

Similar to Tutorial on how to load images in crystal reports dynamically using visual basic 6 and access 2000 (20)

Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
OBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsOBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation Steps
 
Events Registration System Part 1
Events Registration System Part 1Events Registration System Part 1
Events Registration System Part 1
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry university
 
Create a basic performance point dashboard epc
Create a basic performance point dashboard   epcCreate a basic performance point dashboard   epc
Create a basic performance point dashboard epc
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docx
 
Dynamic Web Pages Ch 4 V1.0
Dynamic Web Pages Ch 4 V1.0Dynamic Web Pages Ch 4 V1.0
Dynamic Web Pages Ch 4 V1.0
 
How to Download IDEA for Windows Based ComputersSelect the dow.docx
How to Download IDEA for Windows Based ComputersSelect the dow.docxHow to Download IDEA for Windows Based ComputersSelect the dow.docx
How to Download IDEA for Windows Based ComputersSelect the dow.docx
 
( 5 ) Office 2007 Create A Business Data Catolog
( 5 ) Office 2007   Create A Business Data Catolog( 5 ) Office 2007   Create A Business Data Catolog
( 5 ) Office 2007 Create A Business Data Catolog
 
Database development connection steps
Database development connection stepsDatabase development connection steps
Database development connection steps
 
Fr net programmermanual-en
Fr net programmermanual-enFr net programmermanual-en
Fr net programmermanual-en
 
Creating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolCreating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration tool
 
Oracle ADF 11g Tutorial
Oracle ADF 11g TutorialOracle ADF 11g Tutorial
Oracle ADF 11g Tutorial
 
Oracle Forms
Oracle FormsOracle Forms
Oracle Forms
 
oracle-forms
oracle-formsoracle-forms
oracle-forms
 
CIS 3100 - Database Design and ImplementationProducts on Sale Da.docx
CIS 3100 - Database Design and ImplementationProducts on Sale Da.docxCIS 3100 - Database Design and ImplementationProducts on Sale Da.docx
CIS 3100 - Database Design and ImplementationProducts on Sale Da.docx
 
XPages - The Ties That Bind
XPages - The Ties That BindXPages - The Ties That Bind
XPages - The Ties That Bind
 
- Database Design and ImplementationProducts on Sale Database fo.docx
- Database Design and ImplementationProducts on Sale Database fo.docx- Database Design and ImplementationProducts on Sale Database fo.docx
- Database Design and ImplementationProducts on Sale Database fo.docx
 
A. Lab # BSBA BIS245A-7B. Lab 7 of 7 Database Navigation.docx
A. Lab #  BSBA BIS245A-7B. Lab 7 of 7  Database Navigation.docxA. Lab #  BSBA BIS245A-7B. Lab 7 of 7  Database Navigation.docx
A. Lab # BSBA BIS245A-7B. Lab 7 of 7 Database Navigation.docx
 
Product Supplier59,58,8,2.50CIS 3100 - Database Desig.docx
Product Supplier59,58,8,2.50CIS 3100 - Database Desig.docxProduct Supplier59,58,8,2.50CIS 3100 - Database Desig.docx
Product Supplier59,58,8,2.50CIS 3100 - Database Desig.docx
 

Recently uploaded

Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 

Recently uploaded (20)

Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 

Tutorial on how to load images in crystal reports dynamically using visual basic 6 and access 2000

  • 1. Tutorial on How to Load images in Crystal Reports dynamically Using Visual Basic 6 and Access 2000 By Aeric Poon Introduction This tutorial will show you how to create a Visual Basic 6 project which will generate a report using Seagate Crystal Reports 8.5 Developer Edition. You will save the path of the image files in a MS Access database where it is protected by password. This project will use an external Crystal Report file and will be previewed using Crystal Viewer control. Get Ready In this tutorial, I will use some small images I get from forwarded email. I created a folder name Tutorial where all the files will be store inside this folder. I also created some images with different type like bmp, jpg, gif, png and tif which will be stored inside a folder name Cake. Contents Step 1 Create a Database file using MS Access Step 2 Create a Crystal Reports file Step 3 Create a Visual Basic Project Step 1 Create a Database file using MS Access Run MS Access to create a blank database. Create a folder name Data. In the File New Database dialogue box, type the name dbCake (dbCake.mdb) and click on Create to save this file inside folder Data. You have now created a database file.
  • 2. Click on Create table in Design view. Click the Design button to create a new table. Create the following fields in the new table: CakeID (Text), CakeName (Text), FileName (Text) Set focus at CakeID and then click the Primary Key button to make this field as Primary Key.
  • 3. Close the Table window or click Save button. Save this table name as Cake. Right click and Open table Cake.
  • 4. Insert some records in the table Cake. Save and Close the table Cake. Set a Database Password. For this tutorial, I set the password as yuMMy20.
  • 5. Click OK and Close this file. Now you have a database file ready. Step 2 Create a Crystal Reports file Run Crystal Reports 8.5 Developer. Click on As a Blank Report radio button in the Crystal Report Gallery dialogue box and click OK.
  • 6. You will see a Data Explorer dialogue box. Click on the plus sign of More Data Sources. Click on the plus sign of Active Data and then click on Active Data (ADO).
  • 7. You will see a Select Data Source dialogue box. Choose MS Access Database from the dropdown list and click OK. Browse for the Data folder where we store the database file, click dbCake.mdb and then click OK.
  • 8. A Login dialogue will pop out. Enter yuMMy20 for the password and click OK. Then you will be asking to choose the database again. Click on dbCake.mdb and click OK.
  • 9. You will be brought back to Data Explorer and you will notice there is an icon for ado. We have successfully connected the Report with the database. Click on Add button. You will see a Select Recordset dialogue box.
  • 10. Click on SQL radio button so you can change the query if you want to do so. This is useful if you have WHERE keyword in the SQL statement to filter the records. After you have modified your SQL query, click on OK. Now you can see there is a green tick at the ado icon in Data Explorer. Click Close.
  • 11. Now you will see a Field Explorer dialogue box. Click on the plus sign next to Database Fields:. Click on the plus sign next to ado and you will see all the fields generated from the SQL query.
  • 12. Drag and drop or click on the field and press Enter to insert the field to the report. Add more fields to the report in Details section and resize the width as your preference.
  • 13. Click on Insert Picture icon to insert image file. If you couldn t find the tool, click on menu View, Toolbars and check the Supplementary Tools checkbox. Browse for an image to insert. Resize it to fit your report. Format the appearance of the picture object like adding borders.
  • 14. You can modify the report design by adding lines, box, labels for company title and address or put a logo. Click on Preview tab to show how the report will look like. In this stage, the picture is fixed.
  • 15. Click on menu File and uncheck the Save Data with Report option. Save this report with filename Catalogue (Catalogue.rpt) inside folder Report.
  • 16. Step 3 Create a Visual Basic Project You have the database and report file ready. So, the final step is to create the front-end using MS Visual Basic 6. Create a new Standard EXE by clicking Open. Right click the Toolbar and click on Components
  • 17. Scroll down to look for Crystal Report Viewer Control. Check the checkbox next to it. Click on Designers tab. Check on Crystal Reports 8.5 and click OK.
  • 18. Click on menu Project and click References Look for Microsoft ActiveX Data Objects 2.8 Library (Latest version of ADO control). Check the checkbox next to it.
  • 19. Add also the Crystal Reports 8.5 ActiveX Designer Run Time Library and click OK. Right click the Project Explorer, click Add and then click on Crystal Reports 8.5
  • 20. Click on the From an Existing Report radio button and click OK. Browse for the report file we have designed just now and click Open.
  • 21. On the Crystal Report Expert dialogue box, click No radio button for the upper option. You can notice that Details section is named Section5 in bracket. You can change the name of the section if you like.
  • 22. To hide the FileName field, right click the FileName field and click on Format . On the Common tab, check the checkbox next to Suppress.
  • 23. Hide the Report Header and Report Footer by right click the section separator and click on Suppress (No Drill-Down). If you have made changes in the database table, right click the ado and click verify database.
  • 24. You will be asked for the database password. Key in the password and click OK. A Select Recordset dialogue box will appear. Click OK if the SQL is correct.
  • 25. A message will pop up to inform you that the ado has changed. Click OK. I have added a new field Price in the database table. Click OK to continue.
  • 26. Now, click at the plus sign of ado and you can see the new field is added. Drag and drop the new field and set HorAlignment to crLeftAlign.
  • 27. Rename Picture1 as picCake and Field5 for FileName as adoFileName. Right click inside any section, click on Report and click Save to Crystal reports File .
  • 28. Browse for the report file and click Yes to replace it. Make a backup if you wish to do so. Click OK to proceed.
  • 29. Remove the report designer if you want as we are going to use the external report file. Right click on the Project Explorer and click on Module.
  • 30. Click Open to add the new Module. Insert the following code and save the module as modCake. Option Explicit Public cn As ADODB.Connection Public crx As New CRAXDRT.Application Public Function OpenDatabase() As Boolean On Error GoTo checkErr Set cn = New ADODB.Connection cn.Provider = "Microsoft.Jet.OLEDB.4.0" cn.ConnectionString = "Data Source=" & App.Path & "DatadbCake.mdb" cn.Properties("Jet OLEDB:Database Password") = "yuMMy20" cn.Open OpenDatabase = True Exit Function checkErr: MsgBox Err.Description, vbExclamation, Err.Number End Function The code above is for connecting to the Access 2000 database with password protected using ADO. It is recommended to encrypt the password for higher security. The Crystal Report Application is also set in this module as a Public variable.
  • 31. Click on Form1. Add a button name cmdPrint on Form1. Change the button caption to Print Catalogue. Change Form1 BorderStyle as Fixed Single and caption or icon if you like.
  • 32. Click View Code and insert the following code in Form1 and save it as frmPrint. Option Explicit Private Sub cmdPrint_Click() frmReport.WindowState = 2 frmReport.Show Unload Me End Sub Private Sub Form_Load() If OpenDatabase = False Then Unload Me Exit Sub End If End Sub The above code will connect to the database when the Form loads. If the database failed to load, check the database path, filename and password. If the application failed to start, it will quit. The print button will open a report form which we are going to create later. The report form will be open as a Maximized window. Now add a new form. Click CRViewer to add a Crystal Report Viewer object on this form. Add the following code and save the form as frmReport. Option Explicit Dim rpt As CRAXDRT.Report Dim db As CRAXDRT.Database Dim rs As New ADODB.Recordset Dim WithEvents sect As CRAXDRT.Section
  • 33. Private Sub Form_Load() Screen.MousePointer = vbHourglass Set rpt = crx.OpenReport(App.Path & "ReportCatalogue.rpt") Set db = rpt.Database Set sect = rpt.Sections("Section5") rs.Open "SELECT * FROM Cake", cn, 1, 1 rpt.Database.SetDataSource rs, 3, 1 CRViewer1.ReportSource = rpt CRViewer1.ViewReport CRViewer1.Zoom 1 Screen.MousePointer = vbDefault End Sub Private Sub Form_Resize() CRViewer1.Top = 0 CRViewer1.Left = 0 CRViewer1.Height = ScaleHeight CRViewer1.Width = ScaleWidth End Sub Private Sub Form_Unload(Cancel As Integer) cn.Close End Sub Private Sub sect_Format(ByVal pFormattingInfo As Object) Dim bmp As StdPicture On Error Resume Next With sect.ReportObjects Set .Item("picCake").FormattedPicture = LoadPicture(App.Path & "Cakeck99.gif") 'default If .Item("adoFileName").Value <> "" Then Set bmp = LoadPicture(App.Path & "Cake" & .Item("adoFileName").Value) Set .Item("picCake").FormattedPicture = bmp End If End With End Sub
  • 34. Now we have finished all the coding. Click on Start button to execute the project. Click on the Print Catalogue button.
  • 35. The report preview will show up. Click the printer button if you want to print the report. This is how the trick works. Happy Coding. Please send me an email at aeric80 [at] gmail [dot] com if you found any mistakes in this document or you want to suggest any improvement.