Page 1 of 1
[Solved] Option property "Cancel"
Posted: Sun Apr 02, 2017 9:13 am
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.
Re: Option property "Cancel"
Posted: Sun Apr 02, 2017 1:50 pm
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
Re: Option property "Cancel"
Posted: Sun Apr 02, 2017 6:07 pm
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".
Re: Option property "Cancel"
Posted: Mon Apr 03, 2017 4:09 pm
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 (7.78 KiB) Viewed 2051 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.
Re: Option property "Cancel"
Posted: Mon Apr 03, 2017 5:26 pm
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.