cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BEFORE_REFRESH EVENT ISSUE

Former Member
0 Kudos
432

Hi,

I have a very small validation requirement that I need to perform just before refreshing the Input Form and it is working as per my requirement.

But when I am saving the data from Input Form, again that Before_refresh event is triggering which I don't need.

VBA Code:

Function BEFORE_REFRESH()

If Application.ActiveSheet.Name = "Input Sheet - PM_Annual Budget" Then

answer = MsgBox("Are you sure you want to Refresh the Input Form? Unsaved data will be lost !!", vbYesNo + vbQuestion, "EPM Refresh Data")

If answer = 6 Then

'Conitnure refreshing

  Else

  BEFORE_REFRESH = False

End If

End If

End Function

Please suggest why before_refresh event is triggering after clicking on save button and how to stop it.

Regards,

Bharat

Accepted Solutions (1)

Accepted Solutions (1)

former_member186338
Active Contributor
0 Kudos

Please read my code and comments here:

In general when you press save button you have the following events:

BEFORE_SAVE

... data is saved

BEFORE_REFRESH

AFTER_REFRESH

AFTER_SAVE

If you want to avoid message in BEFORE_REFRESH during save - just set some global variable in BEFORE_SAVE and check it in BEFORE_REFRESH, then clear!

Based on this global variable you will be able to avoid message during save.

Vadim

former_member186338
Active Contributor
0 Kudos

Something like:

Dim blnInSave As Boolean

Public Function BEFORE_SAVE() As Boolean

    blnInSave = True

    BEFORE_SAVE = True

End Function

Public Function BEFORE_REFRESH() As Boolean

    If blnInSave Then

        BEFORE_REFRESH = True

        blnInSave = False

    Else

        If Application.ActiveSheet.Name = "Input Sheet - PM_Annual Budget" Then

            If MsgBox("Are you sure you want to Refresh the Input Form? Unsaved data will be lost !!", _

                vbYesNo + vbQuestion, "EPM Refresh Data") = 6 Then

                BEFORE_REFRESH = True

            Else

                BEFORE_REFRESH = False

            End If

        Else

            BEFORE_REFRESH = True

        End If

    End If

End Function

Former Member
0 Kudos

Thanks Vadim.. It's working now.

Answers (1)

Answers (1)

Shrikant_Jadhav
Active Contributor
0 Kudos

Hi Bharat,

If you are using standard EPM save data button, this is the normal behavior i.e. it save data first and then refresh.

Shrikant