cancel
Showing results for 
Search instead for 
Did you mean: 

YES no boxes using vba

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member186338
Active Contributor
0 Kudos

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)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Vadim,

Many thanks for your help.

No working

Regards

former_member186338
Active Contributor
0 Kudos

No working?

Now working

Or

Not working?

If it's working please select the correct answer.

Former Member
0 Kudos

Sorry, Now working

former_member186338
Active Contributor
0 Kudos

Then select the correct answer!

former_member186338
Active Contributor
0 Kudos
Former Member
0 Kudos

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

former_member186338
Active Contributor
0 Kudos

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