Home > Designing and creating databases > Creating scripts to automate tasks > Scripting with ActiveX Automation (Windows) > ActiveX Automation example (Windows)
ActiveX Automation example (Windows) Private Sub Form_Load()'---------------------------------------------- ' Sample code for accessing FileMaker Pro' in Visual Basic.'' "FileMaker Pro 7.0 Type Library" must be checked' and available in Visual Basic's Project/References. '---------------------------------------------- '---------------------------------------------- ' Declaring Objects and Launching FileMaker '---------------------------------------------- ' Declare object variables Dim FMApp As FMPro70Lib.ApplicationDim FMDocs As FMPro70Lib.DocumentsDim FMActiveDoc As FMPro70Lib.Document ' Launch FileMaker Set FMApp = CreateObject("FMPRO.Application") ' Set the documents object Set FMDocs = FMApp.Documents ' Make FileMaker visible (when launching from automation,' FileMaker remains hidden by default.) FMApp.Visible = True '---------------------------------------------- ' Querying open documents '---------------------------------------------- 'Check the open document count If FMDocs.Count = 0 ThenDebug.Print "No open documents"ElseDebug.Print "Open document count is:"; FMDocs.CountEnd If '-------------------------------------------------- ' Opening a FileMaker database and running a script '-------------------------------------------------- ' Note: A FileMaker file "c:\testing.fmp12" must be available' with a script called "First Script" in order for the following' to work. Dim myOpenFile As Object ' note: can also be declared AsFMPro70Lib.Document Set myOpenFile = FMDocs.Open("c:\testing.fmp12", "","")myOpenFile.DoFMScript ("First Script") '-------------------------------------------------- ' Querying the active document '-------------------------------------------------- Set FMActiveDoc = FMDocs.Active ' Display the active document's name Debug.Print "The active file is "; FMActiveDoc.FullName '-------------------------------------------------- ' Enumerating and closing documents '-------------------------------------------------- Dim TempToc As Object If FMDocs.Count > 0 Then For Each TempDoc In FMDocs Debug.Print "About to close document: "; TempDoc.FullNameTempDoc.CloseSet TempDoc = NothingNextEnd If '---------------------------------------------- ' Clean up and Quit '---------------------------------------------- Set FMDocs = NothingSet FMActiveDoc = NothingSet myOpenFile = Nothing ' Quit FileMaker and release the variables ' (Note: always set the application variable to Nothing after quitting.) FMApp.QuitSet FMApp = Nothing End Sub Related topics Using FileMaker Pro ActiveX Automation (Windows) ActiveX Automation objects, methods, and properties (Windows)