Skip to Content
avatar image
Former Member

YES no boxes using vba

Hi Users,

I am writing a bit of VBA code for BPC 10 NW for a yes / no box.

So if the user selects yes the value saves else it does nothing or refresh's the sheet

This is my code.

Function BEFORE_SAVE()

MsgBox "ARE YOU SAVING TO THE CORRECT MONTH", vbYesNo
If answer = vbYes Then
EAA.SaveAndRefreshWorksheetData
End If
If answer = vbNo Then
EAA.RefreshActiveSheet
End If

End Function

When the user selects no it still gives the option to save the data.

Any advice will be appreciated.

KR

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Nov 16, 2016 at 02:42 PM

    Ups, missed another error in your code! You are not assigning answer variable! Have to be:

    answer = MsgBox("ARE YOU SAVING TO THE CORRECT MONTH", vbYesNo)

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 16, 2016 at 02:26 PM

    Incorrect code!

    The function is triggered by "Save"

    The code have to be:

    Function BEFORE_SAVE()
    MsgBox "ARE YOU SAVING TO THE CORRECT MONTH", vbYesNo
    If answer = vbYes Then
    BEFORE_SAVE = True
    ElseIf answer = vbNo Then
    BEFORE_SAVE = False
    End If
    End Function

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 16, 2016 at 02:34 PM

    Hi Vadim,

    Many thanks for your response, however i am still getting this box when i am pressing no.

    this is the code that is in the VBA script.

    Kind regards

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 16, 2016 at 02:56 PM

    Hi Vadim,

    Many thanks for your help.

    No working

    Regards

    Add comment
    10|10000 characters needed characters exceeded