cancel
Showing results for 
Search instead for 
Did you mean: 

Caturing button click event on system message box

Former Member
0 Kudos

Hi experts ,

I am working on a User Form . When I click on close button of the form it prompts a message 'Do you want to save the changes ?' with three buttons 'YES' 'NO' and 'CANCEL' . I want to catch the event of clicking on 'YES' button to add the code to save or update the records change .

Thanking you ,

Regards,

Mayank Sharma

Accepted Solutions (0)

Answers (1)

Answers (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Mayank,

Is your code triggering that message? Or is your form bound to a UDO?

If your code is triggering the message you can simply check the return value of the message box:


Syntax

Visual Basic

Public Function MessageBox( _

  ByVal Text As String, _

  Optional ByVal DefaultBtn As Long = 1, _

  Optional ByVal Btn1Caption As String = "Ok", _

  Optional ByVal Btn2Caption As String = "", _

  Optional ByVal Btn3Caption As String = "" _

) As Long

Parameters

Text

The message

DefaultBtn

The default button of the message box, either 1, 2, or 3

Btn1Caption

The caption of the first button

Btn2Caption

The caption of the second button

Btn3Caption

The caption of the third button

Return Type

The index of the button that was clicked

If your form is bound to a UDO, then you don't need to manually save or update (this will be handled by the UDO).


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Hi Pedro,

The Message box is auto generated . The code is not triggering the message .

The form is bound to multiple tables . Some of them are UDOs but some are not  . So even if I click YES . The records remain as it is .

Regards,

Mayank Sharma

pedro_magueija
Active Contributor
0 Kudos

Hi Mayank,

Just to be clear, a form cannot be bound to tables. Only to a UDO.

I wouldn't recommend capturing the response on a system message, because there is no "foolproof" way of identifying a system message that is for that specific form.

You can capture the item pressed event of the button and check the type of the form (should be 0 for system messages). But again I wouldn't recommend this.

I'd look into adding a UDO to your form and have it handle the CRUD operations.

Good luck.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn