[Solved] Option property "Cancel"

Discuss the database features
Post Reply
xaxlm
Posts: 6
Joined: Sat Mar 18, 2017 7:49 am
Location: México City

[Solved] Option property "Cancel"

Post by xaxlm »

Hello

I ask for help with the following:

I have a DB with 1 Main Menu through which I access other forms: formEditProduct and formAddProduct. My problem is that when I access formEditProduct and make modifications without saving when I press the "cancel" option the macro opens the "Main Menu" and leaves open The active form.

Can someone guide me as I should adjust the code so that by pressing "cancel" do not open the "Main Menu"?

Here is the code associated with the "Exit" button:

Code: Select all

Sub CloseFormEditProduct
Dim Opcion As Integer
	
	Opcion = MsgBox ("Do you really want to go out?", 36, "Choose an option!")
	
	If Opcion = 6 Then
		ThisDataBaseDocument.FormDocuments.GetByName("formEditProduct").Close
		const sNewDocumentName="Main Menu"
		oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
	End If
	If opcion = 2 Then
	End If
End Sub
Here the DB:
prueba.odb


Thank you.
Last edited by xaxlm on Thu Apr 06, 2017 4:33 am, edited 10 times in total.
LibreOffice 5.2.5.1
Debian 8.7 Jessie & Slackware 14.2
F3K Total
Volunteer
Posts: 1038
Joined: Fri Dec 16, 2011 8:20 pm

Re: Option property "Cancel"

Post by F3K Total »

Try this:

Code: Select all

Sub CloseFormEditProduct
Dim Opcion As Integer
	Opcion = MsgBox ("Do you really want to go out?", 36, "Choose an option!")
	If Opcion = 6 Then
	    oform = ThisComponent.drawpage.forms.GetByName("MainForm")
	    oForm.ismodified = false
	    oForm.cancelRowUpdates
		ThisDataBaseDocument.FormDocuments.GetByName("formEditProduct").Close
		const sNewDocumentName="Main Menu"
		oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
	End If
End Sub
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
xaxlm
Posts: 6
Joined: Sat Mar 18, 2017 7:49 am
Location: México City

Re: Option property "Cancel"

Post by xaxlm »

F3K Total wrote:Try this:

Code: Select all

Sub CloseFormEditProduct
Dim Opcion As Integer
	Opcion = MsgBox ("Do you really want to go out?", 36, "Choose an option!")
	If Opcion = 6 Then
	    oform = ThisComponent.drawpage.forms.GetByName("MainForm")
	    oForm.ismodified = false
	    oForm.cancelRowUpdates
		ThisDataBaseDocument.FormDocuments.GetByName("formEditProduct").Close
		const sNewDocumentName="Main Menu"
		oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
	End If
End Sub
Hi, thanks for the help.

I see that the code is appropriate and it replicates exactly what the previous code does, however it still opens the "Main Menu" form when choosing "Cancel".
I will see if with this cleaner code I can achieve that when choosing "Cancel" do not open "Main Menu".
LibreOffice 5.2.5.1
Debian 8.7 Jessie & Slackware 14.2
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Option property "Cancel"

Post by Arineckaig »

Can someone guide me as I should adjust the code so that by pressing "cancel" do not open the "Main Menu"?
It is not entirely clear what actions you seek from the three (save) options you are offered after choosing "Yes" to "...really want to go out?":
ScreenHunter_262 Apr. 03 14.32.gif
ScreenHunter_262 Apr. 03 14.32.gif (7.78 KiB) Viewed 2012 times
The minimal code amendments suggested below presumes the aim is that "Yes" should save the changes and then abort to the Main menu document, that "No" should similarly abort to the Main menu document without saving any changes, and that "Cancel" should in effect stay with the document that is currently open:

Code: Select all

Sub CloseFormEditProduct
Dim Opcion As Integer
   
   Opcion = MsgBox ("Do you really want to go out?", 36, "Choose an option!")
   
    If Opcion = 6 Then
	  oForm = ThisDataBaseDocument.FormDocuments.GetByName("formEditProduct")
	  const sNewDocumentName="Main Menu"
	     IF oForm.close(true) then 
	       oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
	     END IF
   End If
   If opcion = 2 Then
   End If
End Sub
Please come back if this is not what is required or if you have other problems, but I should warn you designing macros to close form documents that have been changed tends to be complex and is generally well outwith my pay grade.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
xaxlm
Posts: 6
Joined: Sat Mar 18, 2017 7:49 am
Location: México City

Re: Option property "Cancel"

Post by xaxlm »

Arineckaig wrote:
Can someone guide me as I should adjust the code so that by pressing "cancel" do not open the "Main Menu"?
It is not entirely clear what actions you seek from the three (save) options you are offered after choosing "Yes" to "...really want to go out?":
ScreenHunter_262 Apr. 03 14.32.gif
The minimal code amendments suggested below presumes the aim is that "Yes" should save the changes and then abort to the Main menu document, that "No" should similarly abort to the Main menu document without saving any changes, and that "Cancel" should in effect stay with the document that is currently open:

Code: Select all

Sub CloseFormEditProduct
Dim Opcion As Integer
   
   Opcion = MsgBox ("Do you really want to go out?", 36, "Choose an option!")
   
    If Opcion = 6 Then
	  oForm = ThisDataBaseDocument.FormDocuments.GetByName("formEditProduct")
	  const sNewDocumentName="Main Menu"
	     IF oForm.close(true) then 
	       oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
	     END IF
   End If
   If opcion = 2 Then
   End If
End Sub
Please come back if this is not what is required or if you have other problems, but I should warn you designing macros to close form documents that have been changed tends to be complex and is generally well outwith my pay grade.
Hi Arineckaig

Now I have gotten just what I wanted. The "Main Menu" form no longer opens when "Cancel" is pressed. Thanks also to F3K Total, the code is pretty clean.
Here the BD:
pruebaFinal.odb

I consider the subject solved.
Thank you.
LibreOffice 5.2.5.1
Debian 8.7 Jessie & Slackware 14.2
Post Reply