Hello everyone,
am doing a small project and i need to use crystal report with MS access.
i did the connection by wizard
but now am having problem with the path when using it on another PC.
What i need to know is how to connect Crystal report with access but with a relative path...so that i can use it on any PC

how its well explained
Please reply as soon as possible, its a bit urgent
Thanks

Use a crystal report viewer on a form and use this code.

Imports System.Data.Oledb
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Publi Class Form2

Public Where as String
Private Report1 as ReportDocument

Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load

Dim A As CrystalDecisions.CrystalReports.Engine.Table
Dim B As CrystalDecisions.Shared.TableLogOnInfo

Report1 = New ReportDocument()

        Report1.Load(Application.StartupPath & "\ReportName.rpt")
        Report1.RecordSelectionFormula = Where



        For Each A In preport.Database.Tables
            B = tabs.LogOnInfo
            With B.ConnectionInfo
                .ServerName = Application.StartupPath & "\Database Name.mdb"
                .UserID = ""
                .Password = ""
                .DatabaseName = ""
           
 End With


            A.ApplyLogOnInfo(B)

        Next tabs

        Me.CrystalReportViewer1.ReportSource = Report1


End Sub


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Show()
    End Sub

End Class

Use a crystal report viewer on a form and use this code.

Imports System.Data.Oledb
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Publi Class Form2

Public Where as String
Private Report1 as ReportDocument

Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load

Dim A As CrystalDecisions.CrystalReports.Engine.Table
Dim B As CrystalDecisions.Shared.TableLogOnInfo

Report1 = New ReportDocument()

        Report1.Load(Application.StartupPath & "\ReportName.rpt")
        Report1.RecordSelectionFormula = Where



        For Each A In preport.Database.Tables
            B = tabs.LogOnInfo
            With B.ConnectionInfo
                .ServerName = Application.StartupPath & "\Database Name.mdb"
                .UserID = ""
                .Password = ""
                .DatabaseName = ""
           
 End With


            A.ApplyLogOnInfo(B)

        Next tabs

        Me.CrystalReportViewer1.ReportSource = Report1


End Sub


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Show()
    End Sub

End Class

You need to copy the Crystal Report File into the Debug folder together with the
database.

hello, but when i put the crystal report file in debug folder, its not available in VB.NET..any help??

and for the code it said :
name 'preport' is not declared

any help

and thanks for reply am new with this
thank you for helping me

Use a crystal report viewer on a form and use this code.

Imports System.Data.Oledb
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Publi Class Form2

Public Where as String
Private Report1 as ReportDocument

Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load

Dim A As CrystalDecisions.CrystalReports.Engine.Table
Dim B As CrystalDecisions.Shared.TableLogOnInfo

Report1 = New ReportDocument()

        Report1.Load(Application.StartupPath & "\ReportName.rpt")
        Report1.RecordSelectionFormula = Where



        For Each A In preport.Database.Tables
            B = tabs.LogOnInfo
            With B.ConnectionInfo
                .ServerName = Application.StartupPath & "\Database Name.mdb"
                .UserID = ""
                .Password = ""
                .DatabaseName = ""
           
 End With


            A.ApplyLogOnInfo(B)

        Next tabs

        Me.CrystalReportViewer1.ReportSource = Report1


End Sub


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Show()
    End Sub

End Class

You need to copy the Crystal Report File into the Debug folder together with the
database.

hello am getting problem only with the preport

For Each A In preport.Database.Tables

it's saying: name 'preport' is not declared

any help please
thanks

Edited 5 Years Ago by manutd4life: n/a

Add Another (Form2) and there add crystalReportViewer1 there.
In form1 add button and insert below code.

Dim oRpt As New CrystalReport1()
oRpt.Load(Application.StartupPath & "/CrystalReport1.rpt")
Form2.CrystalReportViewer1.ReportSource = oRpt
Form2.CrystalReportViewer1.RefreshReport()
Me.Hide()
Form2.Show()

It Should work. if Your crystal report is created then the code I have posted earlier is for the path to dispaly the report from the application where crystal report is stored

Add Another (Form2) and there add crystalReportViewer1 there.
In form1 add button and insert below code.

Dim oRpt As New CrystalReport1()
oRpt.Load(Application.StartupPath & "/CrystalReport1.rpt")
Form2.CrystalReportViewer1.ReportSource = oRpt
Form2.CrystalReportViewer1.RefreshReport()
Me.Hide()
Form2.Show()

ok am trying this now..will i need to use the codes above


and thank you very much for help..
thank you

ok am trying this now..will i need to use the codes above


and thank you very much for help..
thank you

i just tried it, i havnt use the code above..
when run on my PC..it is good
but when on another PC it looks for the database on my PC


i mean When i move the .exe file the database and the report in another folder
it doesnt run
it looks for the old path
u know what i mean

your DB should be in project so it will take path from the project.
but if your DB is not in project and some where else then copy your DB from your PC in which you have develop the application and paste in your other pc2 where you setup the application exactly with the same path of your pc1 .
when you will run the application, path will match and application will find the DB and I am sure it will work.

hmm ok, but i need to submitt this project...but how the examiner will create the same folder to make the path match.. :/

i think i need to use this code:

Imports System.Data.Oledb
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Publi Class Form2

Public Where as String
Private Report1 as ReportDocument

Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load

Dim A As CrystalDecisions.CrystalReports.Engine.Table
Dim B As CrystalDecisions.Shared.TableLogOnInfo

Report1 = New ReportDocument()

        Report1.Load(Application.StartupPath & "\ReportName.rpt")
        Report1.RecordSelectionFormula = Where



        For Each A In preport.Database.Tables
            B = tabs.LogOnInfo
            With B.ConnectionInfo
                .ServerName = Application.StartupPath & "\Database Name.mdb"
                .UserID = ""
                .Password = ""
                .DatabaseName = ""
           
 End With


            A.ApplyLogOnInfo(B)

        Next tabs

        Me.CrystalReportViewer1.ReportSource = Report1


End Sub


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Show()
    End Sub

End Class

but the only problem is the preport!!

preport not declared

or do u know another way for this, but not to place database in same folder on PC2
because i need to submit this..

By the way thank you very much for helping

Yes You are right in your coding you have not declared the report.
change the coding as below in your code where is required and see if it works.

Dim Report1 As New ReportName()
Report1.Load(Application.StartupPath & "/ReportName.rpt")
Form2.CrystalReportViewer1.ReportSource = Report1
Form2.CrystalReportViewer1.RefreshReport()

For Each A In preport.Database.Tables

Here it is saying
Name 'preport' is not declared

:S

have you tried with code i have sent earlier with seperate button instead of puting in form load

For Each A In preport.Database.Tables
            B = tabs.LogOnInfo
            With B.ConnectionInfo
                .ServerName = Application.StartupPath & "\Database Name.mdb"
                .UserID = ""
                .Password = ""
                .DatabaseName = ""

change the preport into Report1

For Each A In preport.Database.Tables
            B = tabs.LogOnInfo
            With B.ConnectionInfo
                .ServerName = Application.StartupPath & "\Database Name.mdb"
                .UserID = ""
                .Password = ""
                .DatabaseName = ""

change the preport into Report1

i tried this before, but it said tabs it not declared, that y i was a bit loss
what about the tabs now

name 'tabs' is not declared

i tried this before, but it said tabs it not declared, that y i was a bit loss
what about the tabs now

name 'tabs' is not declared

ok i just changed 'tabs' by 'A'..an will test it soon

thanks for helping

for each a in preport.database.tables
            b = tabs.logoninfo
            with b.connectioninfo
                .servername = application.startuppath & "\database name.mdb"
                .userid = ""
                .password = ""
                .databasename = ""

change the preport into report1

heyyy!!! Everything work fine...
Thank you very much
i love you.. lol

thanks a lot..its like u save me while falling from a cliff..u save my world..

Thanks again ;)

This discussion helped me a lot with my thesis! Thank you very much!!!!! All of you are such good people (teary-eyed). . . BIG, BIG, THANKS!!!! :D

This article has been dead for over six months. Start a new discussion instead.