# Close form + warn if record is unsaved using macro [closed]

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hello,

I am building a database and I'm using a switchboard. Opening a form is working with the macro I am using. But the problem is going back to the switchboard. The macro I'm using leaves the form open.

What I want the button to do is: 1. Check if there is an open, unsaved record and if so warn the user to safe his work 2. Close the form that is in use (name of the first form is GSM formulier) 3. Open the switchboard form (whitch is named Switchboard)

I am not sure if the closing and opening are in the right order or it is wiser to first open the switchboard and after that close the form ' GSM formulier' . What is your take on this?

the macro I am using for opening the form is:

Sub OpenSwitchboard
const sNewDocumentName="Switchboard" ' This opens the switchboard
oNewFormDocument=ThisDatabaseDocument.FormDocuments.getbyname(sNewDocumentName).open
End Sub


I am not a programming superhero so any help is welcome.

Many thanks

Tinus087

edit retag reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by Alex Kemp close date 2016-03-05 18:39:02.121572

Tinus087

Did you ever resolve this? I am currently trying to do the same...

( 2014-10-30 16:11:54 +0200 )edit

Sort by » oldest newest most voted

I found this and it seems to work. The scenario is where I am using a switchboard to open forms. When I am done with the open form I click the button, the form closes, and I am back at the switchboard.

Sub OpenFormAppointmentsAll(Event As Object) Dim Form As Object Dim FormDoc AS Object Dim FormCollection As Object Dim DBDoc As Object Dim Args(1) As New com.sun.star.beans.PropertyValue

Form=Event.Source.Model.Parent FormCollection=Form.Parent FormDoc=FormCollection.Parent
DBDoc=FormDoc.Parent

Args(0).Name="ActiveConnection" Args(0).Value=Form.ActiveConnection Args(1).Name="OpenMode" Args(1).Value="open"

REM - to close the current form REM - just before the new one opens REM - get a reference to the current form REM - and then the controller for the form REM - and finally from that FRAME it is in REM - then close that thisComponent.CurrentController.Frame.close( true ) DBDoc.FormDocuments.loadComponentFromURL("AppointmentsAll","_blank",0,Args()) End Sub

more