MsgBox is printing when I press OK or Cancel.

Hi Guys,

What is wrong with this code.

MsgBox " Please load Avery labels No. 5160 in the printer. Then press OK ", vbApplicationModal + vbOKCancel + vbInformation, "Title Company Labels"

The idea is when the user press OK the report prints when the user press cancel the report should not print the msgbox disapears and the user is return to the application.

But right now the report prints when you press OK or Cancel or Close the MsgBox.

Please help.

Rafael
rcleonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
nico5038Connect With a Mentor Commented:
Try:

IF MsgBox (" Please load Avery labels No. 5160 in the printer. Then press OK ", vbApplicationModal + vbOKCancel + vbInformation, "Title Company Labels") = vbOK then
    ' => print command
end if

The messagebox command will "return" the value of the button pressed, best to use the vbOK / vbYes / etc. variables as they "read" easy and Microsoft has a history of changing the numeric value of such return values.

Nic;o)
0
 
Farzad AkbarnejadDeveloperCommented:
Hi,
use

result = msgbox(...)

and check the result in a If-Then-End if statement

-FA
0
 
Farzad AkbarnejadDeveloperCommented:
   If result= vbOK Then  
        'printing report
    Else ' if user clicks on Cancel nothing will happen
        'canceling report
    End If


-FA
0
 
nico5038Commented:
How far are we on thisone Rafael ?

Nic;o)
0
All Courses

From novice to tech pro — start learning today.