Form.shown Event speed


I've moved all my code from my startup form form_load event to the form_shown event because I was having problem with crystal reports in other forms giving me a  "crystal report print Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Every time I was printing or exporting a report

This has fixed the crystal reports issues I was having, the only thing is that now the startup form seems take more time to load, it seems to start "stuck" and then loads everything.

Though personally I don't mind the delay, some users might and I was wondering if there was a way to speed it up a little being that it is in the form_shown event?

Thank you,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you rendering the report when the form is loaded?

You should create a separate thread and load the report there. This will not slow the form
FCapoAuthor Commented:
Hi, the following code is in the form_shown event, I have no reports on this form, this is simply my start up form, the reports are located in other forms in my app;

I have no idea why but if I keep the following code in the form_load event it crashes my application when I try to open the forms that do have reports with "crystal report print Attempted to read or write protected memory. This is often an indication that other memory is corrupt." :

having it in the Form1_Shown event seems to solve the crash but it creates a delay when the start up form is first shown

Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

        clientData = New Clients
        cliDataSet = clientData.getCliDataSet
        cliBindingSource = New BindingSource

        clientDataExtra = New clientsExtra
        clidatasetExtra = clientDataExtra.getCliDataSet
        cliBindingSourceExtra = New BindingSource

        rectAccessData = New ClientsAccess
        recAccDataSet = rectAccessData.getRecDataSet
        AccessBindingsource = New BindingSource

        clientAccessData = New ClientsAccess
        cliAccDataSet = clientAccessData.getrelateddata
        cliAccessBindingsource = New BindingSource

        timeData = New timesheet
        timeDataSet = timeData.getTimesheetHoursDataSet
        timeBindingSource = New BindingSource

        timeData1 = New timesheet
        timeDataSet1 = timeData1.getTimesheetHoursDataSet2
        timeBindingSource1 = New BindingSource

        budgetData = New ClientsAccess
        budgetdataset = budgetData.getBudget
        budgetBindingsource = New BindingSource

        With cliAccessBindingsource
            .DataSource = cliAccDataSet
            .DataMember = "projets"
        End With

        With budgetBindingsource
            .DataSource = budgetdataset
            .DataMember = "budget"
        End With

        With timeBindingSource
            .DataSource = timeDataSet
            .DataMember = "FeuillesDeTemps"
            .Sort = "ID"
        End With

        With timeBindingSource1
            .DataSource = timeDataSet1
            .DataMember = "FeuillesDeTemps"
            .Sort = "ID"
        End With

        With AccessBindingsource
            .DataSource = recAccDataSet
            .DataMember = "recevable"
        End With

        With cliBindingSource
            .DataSource = cliDataSet
            .DataMember = "DataTable"
            .Sort = "sName"
        End With

        With cliBindingSourceExtra
            .DataSource = clidatasetExtra
            .DataMember = "DataTable1"
        End With

        With cliCbx
            .DataSource = cliBindingSource
            .DataBindings.Add("text", cliBindingSource, "sName", False, DataSourceUpdateMode.Never)
            .DisplayMember = "sName"
        End With

        With extraCbx
            .DataSource = cliBindingSourceExtra
            .DataBindings.Add("text", cliBindingSourceExtra, "lCusId", False, DataSourceUpdateMode.Never)
            .DisplayMember = "lCusId"
        End With

        DataGridView1.DataSource = cliBindingSource

        For i = 0 To DataGridView1.Columns.Count - 1
            If i = 1 Then
                DataGridView1.Columns(i).Visible = False
            End If

        DataGridView1.Columns(1).HeaderText = "Nom du client"
        DataGridView1.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

        SimpleId.DataBindings.Add("text", cliBindingSource, "lId")
        cliSimplyExtra.DataBindings.Add("text", cliBindingSourceExtra, "lCusId")

        cliRue1.DataBindings.Add("text", cliBindingSource, "sStreet1")
        cliRue2.DataBindings.Add("text", cliBindingSource, "sStreet2")
        cliVille.DataBindings.Add("text", cliBindingSource, "sCity")
        cliPrv.DataBindings.Add("text", cliBindingSource, "sProvState")
        cliCode.DataBindings.Add("text", cliBindingSource, "sPostalZip")
        cliCourriel.DataBindings.Add("text", cliBindingSource, "sEmail")
        CliTxt.DataBindings.Add("text", cliBindingSource, "sCntcName")
        cliTelBur.DataBindings.Add("text", cliBindingSource, "sPhone1")
        cliTelCell.DataBindings.Add("text", cliBindingSource, "sPhone2")
        cliFax.DataBindings.Add("text", cliBindingSource, "sFax")
        cliTelDom.DataBindings.Add("text", cliBindingSourceExtra, "sUsrDfnd1")


        If My.Settings.recevReminders = "yes" Then
        End If

        If My.Settings.timesheetReminders = "yes" Then
            My.Settings.timesheetId = timeDataSet.FeuillesDeTemps.Compute("max(ID)", "")
        End If

        TabControl1.SelectedIndex = 1
        TabControl1.SelectedIndex = 0

    End Sub

Open in new window

CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

FCapoAuthor Commented:
Any ideas?

Why does having my code in the startup Form1_Shown instead of Form1_load event impact crystal reports being able to print or export in another form?
I have no idea.

Most likely it is because of when the event fires in relation to when the report loads


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FCapoAuthor Commented:
After looking further,

I've come to the conclusion that it has to do with the Access format of my database, which is .ACCDB

I've tried converting it to the standard .MDB version and updating it in my datasets, afterwards crystal report was no longer giving me this error when printing or exporting;

I've attached a screenshot of how Crystal Reports is set to connect to my database, when switching over from Provider=Microsoft.ACE.OLEDB.12.0  to Provider=Microsoft.Jet.OLEDB.4.0 it seemed to no longer give me this error.

I rather keep the .ACCDB since I have a few apps connecting to it, hopefully you can look at the screencapture and there may be a different way to connect to it that wouldn't provoke this error?

Thank you
What version of Crystal?

DId you download the Office database connectors?

FCapoAuthor Commented:
I have the full crystal report version running with visual studio 2010 and the crystal reports Support Pack 12 (v.

Yes I believe I have the right Office database connectors, I only get these issues when crystal reports sees more than one connection is made to the .ACCDB database, using the JET connection crystal reports doesn't give me any issues...
CR XI R2 ( was built for .Net 2.0.  Are you running in a later .Net framework?

You probably want to change the reports to use the .Net version

FCapoAuthor Commented:
I'm running .net framework 4, How can I about changing the report to use the .Net version? Is there a setting I can change somewhere?

Thank you
You should be able to install the CR for .Net then import the report into the application and save it.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.