cancel
Showing results for 
Search instead for 
Did you mean: 

Problem open report

Former Member
0 Kudos

Hi.

Can help me with this please:

How can I open a CrystalReportViewer in my project SDK. Because I have this problem when my applications debugins this open the Viewer with the report. But when my report is created with parameters this show this error.

activex control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment

Regards,

Jose

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Jose,

If you are working in .NET environment, you can try adding "[STAThread]" before main() like:

[[STAThread]]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

}

Best Regards,

Jay.

Edited by: Jay Ji on Jun 26, 2008 11:39 AM

Former Member
0 Kudos

hi Jay. Thanks for your help.

I find this problem:

When in my addon I have a event that open the report this show the error. But when I open the report outsite the event this is fine.

THIS IS MY CODE:

Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean)handles SBO_Application.MenuEvent

Dim openR as new Report

openR.ShowDialog()

End Sub

How can I use your code?

Regards,

Jose

Former Member
0 Kudos

I use your code in my event but still show the message.

This is this the code of the event:

Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.MenuEvent

Application.EnableVisualStyles()

Application.SetCompatibleTextRenderingDefault(False)

Application.Run(New OpenReport)

End Sub

But if I use a report without parameter this working fine.

What can I do?

Regards,

Jose

Former Member
0 Kudos

Hi,

From your catching event , you need to open a single thread like that:

Imports System.Threading

Item Event Sub:

Dim thread As Thread = New Thread(New ThreadStart(AddressOf CallingDialog))

thread.SetApartmentState(ApartmentState.STA)

thread.Start()

thread.Join()

End Sub

Private Sub CallingDialog()

Dim MyWindow As WindowWrapper = Nothing

Dim MyProcs() As Process

MyProcs = Process.GetProcessesByName("SAP Business One")

If MyProcs.Length = 1 Then

MyWindow = New WindowWrapper(MyProcs(0).MainWindowHandle)

End If

FileDialog = New System.Windows.Forms.OpenFileDialog

FileDialog.ShowDialog(MyWindow)

End Sub

  • the WindowWrapper will open the FileDailog in the front and not in the background.

Moti.

Former Member
0 Kudos

Thanks for your help Moti.

I add this code but get the following message:

Type 'WindowWrapper' is not defined.

I need import or declared this ?

I am using visual .net 2008.

Regards,

Jose

Edited by: Jose Villarreal on Jul 24, 2008 4:32 PM

Nussi
Active Contributor
0 Kudos

Jose,

i add parameter to a crystal-report like this

vb6 code


Report.ParameterFields.GetItemByName(sParamName).ClearCurrentValueAndRange
Report.ParameterFields.GetItemByName(sParamName).AddCurrentValue CLng(sParamValue)

might help you

lg David

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Jose,

You can write the CallingDialog function without window wrapper patch:

Private Sub CallingDialog()

FileDialog = New System.Windows.Forms.OpenFileDialog

FileDialog.ShowDialog

End Sub

About your question , if you have problem with the appearance of the FileDilaog, add this class of window wrapper:

Public Class WindowWrapper

Implements System.Windows.Forms.IWin32Window

Private _hwnd As IntPtr

Public Sub New(ByVal handle As IntPtr)

_hwnd = handle

End Sub

Public ReadOnly Property Handle() As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle

Get

Return _hwnd

End Get

End Property

End Class

Moti

Former Member
0 Kudos

Hi All,

I have the same scenario. I have applied the code given above but to me the problem remains the same.

For your reference I copy my code here:


Module MainSub
    Public Sub main()
        Dim thread As Thread = New Thread(New ThreadStart(AddressOf CallingCode))
        thread.SetApartmentState(ApartmentState.STA)
        thread.Start()
        thread.Join()

        Dim AJMReports As reports
        AJMReports = New reports()
        System.Windows.Forms.Application.Run()
    End Sub

    Private Sub CallingCode()
        Dim Filedialog As Printouts
        Filedialog = New Printouts
        Filedialog.ShowDialog()
    End Sub
End Module

"Printouts" above is my vb.net form to show crystal reports.

Can anybody guide me where I am doing wrong?

Many thanks in advance for any help.