Ladies and Gentelmen, I seem to have an issue with OCX in Navision. Basically what i am trying to do is, to use an OCX to open a VB form. Unfortunately, I get this error: Non-modal forms cannot be displayed in this host application from an ActiveXDll, ActiveX Control, or Property Page. Any one has any suggestions on how to get pass this issue? Why am i using a VB form and not a NAVISION one, well this has to do with the fact that VB forms are more flexible. So if any one has any suggestion on how to fix this problem I would really appreciate it. regards Omair
You should be creating a Form in Standard EXE and call the Navision OCX from that to use VB Forms instead of Navision Forms. I think, you are trying to create a form from ActiveX Control project. I think, you need to choose the VB project type correctly.
Thanks Mani, This however does not solve my problem. Basically what I am trying to do is to pass variables from the VB form back to Navision, or display variable from Navision in the VB form. If I make a Standard EXE I will only be able to display the form. I need to output and input variable to and from the form. regards Omair
Dear Omair r u doing like this Open visual Basic , go in Project Components (CTL-T), select CFRONT Ole Control Module, from the toolbox select that control (OCX) Place it on the form and go in the code of Vb and type CFRONT1. , you will get the whole list of functions and properties of CFRONT.
Hi Ajay, Nope that is not what I am trying to do. Ok, basically, I made an OCX with Form1. In the OCX I write a procedure that opens Form1. I will call it ShowForm. It looks somehting like: Sub ShowForm() Form1.Show end sub Then I register the OCX in Navision, and call the OCX.ShowForm. I get the nonModal error. Thats where i seem to get stuck. The idea is that if i can display Form1 using the OCX, then Variables entered into Form1 can be passed back to Navision with a return procedure. Well thats the idea. Hope this is clear. thanks and regards Omair
Omair, use Form1.Show vbModal Torsten
Originally posted by OmairZ
Hi Ajay, It looks somehting like: Sub ShowForm() Form1.Show end sub
no torsten , i do not think he can open the form like this. omair in spite of making sub (procedure) use function like function ShowForm() Form1.Show end function
Trosten you are absolutely RIGHT! I finally was able to open the form with vbmodal. Thanks and regards Omair
There are three types of COM-components: OCX, DLL and EXE (not to be confused with an ordinary executable). Of these, only EXE components are able to show non-modal forms. OCX and DLL components will return the error message you got. Modal forms will work well, though. If you need to display your form in non-modal way, I suggest you compile your VB project as an EXE component. There will be no difference in the way you call it from Navision except that your C/AL variables will be of type Automation instead of OCX, but the forms will work.
Omair, Looks like you found your solution. Just in case, here’s how we implement one of our VB DLLs: The iShowType parameter in the VB Sub below is passed as vbModal (1) and we also have the capability of passing iRounding when displaying the VB window. Navision calling convention is below. Public Sub ShowMain(iShowType As Integer, Optional iRounding As _ Integer = 1, Optional dDate As Date) ’ Normally (almost always) call with vbModal (1) ’ iRounding sets the form’s rounding default If iRounding = 1 Then m_frmMain.optNone.Value = True ElseIf iRounding = 2 Then m_frmMain.optUp.Value = True ElseIf iRounding = 3 Then m_frmMain.optDown.Value = True End If If DatePart(“yyyy”, dDate) < “1900” Then dDate = Date End If ’ Default NAGS effective pricing date m_frmMain.fpdtPriceDate.DateValue = Format(dDate, “YYYYMMDD”) m_frmMain.Show iShowType End Sub Navision function GetNAGS() showing how VB’s ShowMain() sub is called. In the example we are calling VB, users selects data from an SQL table(s), presses Ok then the data is returned via ADO recordset for programmers use. GetNAGS(VAR autRsSelected : Automation “‘Microsoft ActiveX Data Objects 2.6 Library’.Recordset”;bAppClosesRecSet : Boolean) : Boolean // Remember, you’ll need to close autRsSelected when you are done with it. objNAGS is a reference to our DLL. IF (NOT CREATE(autRsSelected)) THEN BEGIN EXIT(FALSE); END; iNagsStatus := 1; // Always open Modal IF CREATE(objNAGS) THEN BEGIN // You will have to close and clear the autRsSelected Record Set // in the calling function IF (NOT objNAGS.GetIsError) THEN BEGIN objNAGS.AppClosesSelected(bAppClosesRecSet); objNAGS.ShowMain(iNagsStatus); IF bAppClosesRecSet THEN BEGIN // Assign the record set locally to use in Navision… // Make sure you close this recordset when done! autRsSelected := objNAGS.GetSelected(); END; CLEAR(objNAGS); EXIT(TRUE); END; END; EXIT(FALSE); *************** Hope this helps. We use the routine to allow the user to get external data and populate Navision Sales Lines from an external SQL database. Works great and doesn’t release focus to Navision until the process is shut down by the user. Bill
Thanks Bill, The info you have given is very useful. It took me a good 2 to 3 hourse to figure out the vbmodal thing. Although i have been programming for some time, it just goes to show, you cannot know everything. Thansk and regards Omair