Skip to Content
0

YES no boxes using vba

Nov 16, 2016 at 02:20 PM

48

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Vadim Kalinin Nov 16, 2016 at 02:42 PM
0

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)

Share
10 |10000 characters needed characters left characters exceeded
Vadim Kalinin Nov 16, 2016 at 02:26 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Nov 16, 2016 at 02:34 PM
0

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


bupvc.png (12.7 kB)
zrsan.png (13.3 kB)
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Nov 16, 2016 at 02:56 PM
0

Hi Vadim,

Many thanks for your help.

No working

Regards

Show 4 Share
10 |10000 characters needed characters left characters exceeded

No working?

Now working

Or

Not working?

If it's working please select the correct answer.

0
Former Member
Vadim Kalinin

Sorry, Now working

0

Then select the correct answer!

0
0