Using FileMaker Pro ActiveX Automation (Windows)
The FileMaker Pro Type Library is included in the FileMaker Pro executable. It is not a separate file. The FileMaker Pro Type Library was registered on your computer when you installed FileMaker Pro.
In Visual Basic, add "FileMaker Pro Type Library" to the list of Available References in your project.
Important You must add the FileMaker Pro Type Library to the list of available type libraries in the application you will be using to implement your ActiveX Automation document. If you don't add the type library, you won't be able to address FileMaker Pro via ActiveX Automation.
The method for adding this library varies in the different ActiveX Automation authoring tools. Consult the manual that came with your ActiveX Automation authoring tool if you are unsure of how to do this. The following procedure explains how to do this in Microsoft Visual Basic.
FMPro70Lib appears in the Visual Basic Object Browser once the project references include the FileMaker Pro Type Library. All of the objects, methods and properties that FileMaker Pro exposes for Automation control are now available.
Declare the FileMaker Pro as the Application object each time you create an ActiveX Automation script or application to control FileMaker Pro. This can be done with a single line of code at the top of your Automation document, where it appears with your other definitions.
Dim FMProApp As FMPro70Lib.Application
Dim FMProApp as FMPro70Lib.Application
Set FMProApp = CreateObject("FMPRO.Application")
Set FMProApp = GetObject(, "FMPRO.Application")
Notice the comma, which indicates that the first argument to GetObject — a path to a disk file — has been omitted. The comma is required because under some circumstances GetObject takes a filename as its first argument. To retrieve an instance of FileMaker, however, you must omit the filename argument, or an error will occur.
To run a FileMaker Pro script via ActiveX Automation, call the DoFMScript function with the name of the script as the variable.
Dim FMProApp as FMPro70Lib.Application
CreateObject("FMPRO.application")
Dim FMProDocs, FMProDocs.Open("c:\MyFile.fmp12","","")
Dim FMProDoc
FMProDoc.DoFMScript ("MyScript")
Set FMProDoc = nothing
When FileMaker Pro is launched by Automation, it will run hidden by default. You can use the visible property to hide or show FileMaker Pro.
When an automation object is referenced, a reference count increments to let FileMaker know that a process is using that object. In Visual Basic, an object is reference counted every time you set the declared variable to a FileMaker object, for example:
Dim FMDocs as FMPro70Lib.Documents
Set FMDocs = FMApp.Documents
Set FMDocs2 = FMApp.Documents
FileMaker Pro uses the
Documents.Open(filename As String, accountName As String, password As String) method. If the
accountName and
password arguments are empty strings, the file will be opened as a client user.
FileMaker Pro scripts called directly by Automation may interrupt each other.
FileMaker Pro scripts called from within other FileMaker Pro scripts will run in order, as expected.
It is not possible to open a hosted file using ActiveX Automation alone. To open a hosted file using Automation, you can either open the hosted file directly using the FileMaker Open dialog box, and then access the file using Automation, or you can write a FileMaker Pro script that opens the hosted file, and then call that script via Automation.