Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Need For Cancel Click On Message Box To Exit Sub?


I have a code that creates new files for each w/s in master workbook but in A3 format, but this won’t happen if their default printer is only A4. In this case a Message Box appears asking the user to choose an A3 printer from a Dialog box. As a complete VB complete novice that fumbles in the dark, I have inherited this code from other forum users. So can anyone suggest how to modify my existing code to suit my needs?
What I would like it to do is; - Show the OK / Cancel buttons at the "Choose an A3 printer" Message Box. But for the Cancel button to exit the Sub at that point if clicked. (As the wording on the Message Box would suggest.)


Extract:

.BlackAndWhite = False
.Zoom = 69
.PrintErrors = xlPrintErrorsDisplayed
On Error GoTo PageSizeError
ActiveSheet.PageSetup.PaperSize = xlPaperA3
On Error GoTo 0

AllDone:
Application.ScreenUpdating = False

Exit Sub

PageSizeError:
Dim Response As VbMsgBoxResult
Response = MsgBox("Couldn't set the page size to A3." & vbCrLf & _
"Click 'OK' to choose an A3 printer and continue. " & vbCrLf & _
"Or click 'Cancel' to stop file creation and exit.", _
vbExclamation + vbOKCancel)
If Response = vbOK Then
Application.Dialogs(xlDialogPrinterSetup).Show
Application.ScreenUpdating = False

Resume

Else

Resume AllDone
End If
End With

End Sub

Any help appreciated.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
[VB6] Exit Sub On CommonDialog Cancel
Hello everyone! I am using Microsoft Visual Basic 6. How do I exit the sub when the "Cancel" button is clicked in the CommonDialog? Thank you!

Telling The Difference Between A OK Click And A Cancel Click On A Common Dialog Box..
When I load a mp3 file into my MMControl, it should then go and get the ID3 tags from it. But, I have a common dialog box so the user can specify what file they want to open. Now when they click the Cancel button it gives me an error because it's trying to get the ID3 tags from a file that blank filename.

To make a long story short: How do I tell when a user clicks the cancel button instead of the OK button on a File Open common dialog box.


Thanx,
Ben

How To Programmatically Exit Or Cancel A Menu Or Popup.
Hi,

  I was wondering if anyone knows how to tell an MDI or other form to cancel or exit its menu. Here is my problem. I have an app I am writing that has a treeview. You can either right-click or press Shift-F10 to bring up a context menu. It is working fine, except for one little thing. I use the TreeView_KeyUp sub to check for Shift-F10. Once I see that Shift-F10 is pressed, I use PopMenu to bring up a popup menu. I have the following code to find the x,y coordinates of the node (I thought this was pretty nifty):


Public Function GetTvwNodeRect(Tvw As TreeView) As Boolean

    lItemHandle = SendMessage(Tvw.hWnd, TVM_GETNEXTITEM, ByVal TVGN_CARET, 0&)
    If lItemHandle Then
        ' For some reason, the message fails if the handle is not in the .left
        ' member of the structure.
        r.Left = lItemHandle
        SendMessage Tvw.hWnd, TVM_GETITEMRECT, 1, r
        GetTvwNodeRect = True
    End If
End Function

  The problem is this. Once the popup is clicked and the action taken (maybe a new form opened), the first menu item ('File') is inset to indicate that the menu is still active. In order to actually have the form that opened as a result of the context menu selection receive keystrokes, you have to first press Esc, Alt, Tab or click on the form with the mouse. While it is minor, I want it to be right. If the user forgets this and hits a key that activates a menu item, it could spell trouble. I have a SendKey "{TAB}+{TAB}" line in and it seems to work, but it is still a band-aid. Is there a message I can send via the SendMessage API that will cancel the menu? Please let me know if you have an answer.

Thanks,
Tony

Help Me With Ok And Cancel Message Box!!
does n e 1 know how to write example code for a ok or cancel message box???

Cancel Message....
I have a program that displays a messagebox when an event happens then continues to process the code in the event. Is there anyway to send a message to the program from another program that will allow me to cancel what happens after I hit ok on the message box. So I will send key {ENTER} to close the message box then I want the program to exit the event sub, all from another application. Thanks in advance!!

Message Box Cancel
How do you make a cancel button on a Message Box do nothing ?

Are You Sure You Want To Exit Message?
I want it so when you press the "x" button in the corner of my app it asks you if you're sure you want to exit.

I know you use this section to do it


VB Code:
Private Sub Form_Unload(Cancel As Integer)End Sub


but when I use the code I have on a command button for this whether I press no or yes doesn't matter..... It exits anyway.
Here is complete code


VB Code:
Private Sub Form_Unload(Cancel As Integer)On Error GoTo ErrorHandler Dim Msg, Style, Title, Response, MyStringMsg = "Are you sure you want to exit FS Xml Pro 1.1 ?"Style = vbYesNo + vbQuestion + vbDefaultButton1Title = "FS XML Pro"Response = MsgBox(Msg, Style, Title)If Response = vbYes Then   MyString = "Yes"EndEnd IfErrorHandler:End Sub

Exit Message Box
How would one make a message box that gives the option to exit, or not to exit, so that clicking the "no" buttonwould make it so you DON'T leave the program?

Debug Message When Cancel Save As
I am having a difficult time working out this code. I am using the auto close code to go through some items to check before the user closes the file. At the end of the auto_close, I have set the macro to automatically save the file to a specific directory and filename. If the user cancels the save as, they receive a debug message.

Can anyone help? My code is listed below.

Sub Auto_Close()
'

If Worksheets("Funding Sheet").Cells(2, 21).Value = "" Then
MsgBox ("You must enter the customer name and contract number.")
End If
If Worksheets("Page 5").Cells(35.2).Value > 0 Then
Worksheets("Page 2").Cells(12, 18).Value = Worksheets("Page 5").Cells(35, 2).Value
End If
If Worksheets("Page 4").Cells(28, 6).Value = "" Then
MsgBox "You must enter the funding date."
End If

storename = Worksheets("Page 1").Cells(2, 21)
ActiveWorkbook.SaveAs Filename:= _
"S:LeasingFundings & Input Sheets2004New Input Sheets" & storename & "input sheet.XLS" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Thanks!

Excel - Cancel Out Of Error Message From VBA
I am using VBA to access a webpage, populate the search criteria, and download the data results in an Excel spreadsheet. When the website tries to download the data, I get the following Excel error: "File error: data may have been lost". If I switch to Excel manually (from Internet Explorer) and click either OK or ESC, the error goes away and the file downloads, without losing any data. I have contacted the data provider and they say there is no way around this error since I already have Excel open.

So, I am wondering if there is a way to cancel out of the error message automatically from VBA, or do not display this type of error. I have tried activating the window then closing it, but when I do this, the spreadsheet, not the error message, is considered the active window.

Any suggestions?

Cancel Printing Got Error Message
I use code something like Printer.EndDoc .. When I cancel, I got the error message "Printer error". Why? how to handle this error so that when I click the cancel, I did not get error message like this. When I click save, It fine.

Auto Click Yes / No (OK/Cancel)
URGENT!

This seems to be an issue that a lot of people would have run into; however, I couldn't find the answer anywhere so here is the issue:

I am running a program call: Introspect Batch made by Zantaz company. Each time I run an update batch file gainst the database, there is a pop-up message saying "you will override the current data... do you want to continue?"

If I only run 1-2 update files, that's no problem, but it is an issue when you run 200-300 update batches. You have to be at the computer to click Yes, otherwise the program just sit there.

I am looking for a quick way to by pass this. Do you know if there's an easy way or a small utility that I can tell it to click the Yes button each time such a pop-up window shows up?

Thanks...

-Ezfriend

Cancel Right Click In Text Box
Anyone know how to get rid of the edit menu when you right click in a text box?

thanks

Cancel A Mouse Click
Does anyone know if you can catch a mouse click and cancel it so it has no effect on the program.

Sorta like the keyascii = 0 scenario.....etc etc.

What i am trying to do is turn a menu item into a heading. I'm aware you can set enable to false but the text is then ghosted and hard to read.

Dazza.

Cancel A Click Event
Hi,

Let's say that a user clicks on a listbox's item, the click event is generated. What if after some validation, the program should move back to the previous index because something is missing etc.

How can I cancel a click event?
I tried to change the listindex to the old one, but that generates another click event.

Thanks,

Prints Even Tho Click CANCEL!! Help!
I'm not sure if you can use KillDoc to stop printing if it was set to the printer from the commondialog box, but you might try this. The bold stuff is what I added to your code.

VB Code:
[b]Private Sub cmdPrint_Click() On Error GoTo PrintError CommonDialog1.CancelError = True[/b]CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums If rtbWrite.SelLength = 0 Then    CommonDialog1.Flags = CommonDialog1.Flags + cdlPDAllPagesElse    CommonDialog1.Flags = CommonDialog1.Flags + cdlPDSelectionEnd If CommonDialog1.ShowPrinterPrinter.Print ""rtbWrite.SelPrint CommonDialog1.hDC[b]Exit Sub PrintError:    Printer.KillDocEnd Sub[/b]

How To Exit From A Form With A Confirmation Message?
Hi,
I want to put a confirmation message in my application when the user click the close button. I cannot do it by coding in Unload event of my form. Any help would be greatful.


Thanking you

Haris

_____________________________________________________________________


Edited by - harisraz on 9/16/2004 12:17:29 AM

Color Change When Click Cancel
I use common dialog to change the color..

My color is red.. But when I click cancel on the common dialog, it color will black..How I can retain the color if I click cancel button in common dialog?Only change the color when I select the color.

CommonDialog1.ShowColor

MapCompactMaps.BackColor = CommonDialog1.Color

How Can I Ignore The Vaildation If I Click On Cancel?
Hi,

For example, I have a Text1_Validate sub to valid the customerID.
When I click on the new button and click on cancel button, the program will keep prompting to enter a vaild value continously.

Is it possible to set the validate sub to false when the cancel_click is activated?

Why Does It Come Up Runtime Error '13' When I Click Cancel?
I am working on a simple program just to add students to a list, for a school. Well, that's what I've come up with so far, anyway. For some reason it comes up with "Runtime Error '13' when I click cancel. Here is my code so far.


Private Sub cmdStudentEntry_Click()
Dim NoOfLoops As Integer

Dim StudentName As String

NoOfLoops = InputBox("How many students do you want to add?")

For i = 1 To NoOfLoops

StudentName = InputBox("Enter a student name:")

lstStudents.AddItem (StudentName)

Next i
End Sub

My command button is called "cmdStudentEntry" and my list box "lstStudents"

How To Cancel The Click Event In A DataGrid?
I'm using a DataGrid and want to capture a click event and prevent a row change. I want to check for certain conditions in the recordset that is bound to the grid and then somehow cancel the row change if those conditions are true.

The RowColChange event only happens after the row change and it seems kind of clunky to move back to the last row and check the conditions and then allow the move if the conditions are false.

Anyone have any ideas?

Comon Dialog Cancel Click
im using common dialogs to save my files and every now and then when i click on cancel it saves the file anyway but with no extention.
is there a way to make sure that it only does so on a save click, that on a cancel click it exits the dialog?

Signature -----------------------------------------------------------------------------------------------------Code:Private Sub Form_Load() 'Print to from, code my problems!
     Form1.Print "CanT SleeP!..... MusT PrograM!!!" & vbCrLf & "I need coffee, WhErE iS mY CoFfEe?!"
End Sub 'All things come to and end
------------------------------------------------------------------------------------------------------------------

Directing What Happens When Cancel Is Click On InputBox
I am trying to direct what happens when the cancel button on an inputbox is clicked. I want the current form to disappear and the menu form to reappear. It doesn't happen, the frmEmployeeData shows when the Cancel or OK is clicked. I tried to unload the Employee form rather than hide, but then I get an error (object unloaded) immediately on my Menu form. Here is the code. Any help would be greatly appreciated.



private Sub Form_Load()
Dim EmployeeNumber as Variant
frmEmployeeData.BackColor = &HC00000
frmEmployeeData.Show
TabStrip1.Visible = false
Frame1(0).Visible = false
Frame1(1).Visible = false
Frame1(2).Visible = false
Frame1(3).Visible = false
'
EmployeeNumber = InputBox$("Employee Number ('S' for Search)")
If EmployeeNumber = "" then
frmEmployeeData.Hide
frmMenu.Show
End If
'
'Add employee data code
'
TabStrip1.Visible = true
Frame1(0).Visible = true
Frame1(1).Visible = true
Frame1(2).Visible = true
Frame1(3).Visible = true



for i = 0 to Frame1.Count - 1
With Frame1(i)
.Move TabStrip1.ClientLeft, TabStrip1.ClientTop, _
TabStrip1.ClientWidth, TabStrip1.ClientHeight
End With
next i

DoTabLogic

End Sub




Thank you,
Catrina

SysTray Right Click ---> Exit
Is there any way to simulate a right-click on the MSN Messenger 6 SysTray icon? I need my VB Program to select the "Exit" menuitem.

I do not want to use the WM_CLOSE command, or TerminateProcess...

SysTray Right Click ---> Exit
Is there any way to simulate a right-click on the MSN Messenger 6 SysTray icon? I need my VB Program to select the "Exit" menuitem.

I do not want to use the WM_CLOSE command, or TerminateProcess...

Creating A Message Box That Asks Ok Or Cancel Before Running A Macro
I am trying to create a message box that says Are you sure you want to run this Macro, it cannot be undone! with Ok and Cancel as the buttons. If the user clicks ok, then obviously run the macro, and if Cancel just quit. This is to prevent an accidental click which cannot be undone. I cannot seem to figure this out. Thanks in advance.

Exit VB Program With Message Or Return Code
I've looked high and low and haven't been able to find any doc or examples on how to exit a VB program with a Return Code or Exit message (not a message box),,,

Basically I've got an app that can be called from Cmd/Dos prompt,, When the program exits I need to be able to pass a Return Code or Exit message. Any of you good folks got any ideas,,, Any help would be appreciated,,, Thanks in advance

How Can I Hide Message That Is Diplayed When We Exit From VB6 Program
Hi ALL
Hope u all fine and enjoying good health.
i developed application in VB6 And make its exe for client use. when client exit from exe following message is appeared
"The instruction at "0x3f702bf", referenced at memory "0Xb803f702" the message could not be read . click ok to terminate program."

How can i get rid from this message . i want that this message did not appear

Thanking U in advance

Bye.

How To Cancel The Click Event In The Image Control
I inserted image control (to make it a background for some controls) on the sheet and then I placed some controls like command after I made the image "send backward" and controls "send forward" . When I run the project the controls appear on the image. But when I click on the image the controls disappear and then appear again when I move the mouse away from the image. How to fix this problem. By the way I tried to make the propert of image, Enable= false, But it didn't success .

thank you for help.

Why Error If I Click The Cancel Dialog Box Button?
Hi there. I want to know how to trap the error occur when I click cancel button in a dialog box control. Can anybody help?

Bad File Name Or Number When Click Exit
Hi, All!

I finally got the command buttons (Search By Name;Search By Number;View Entire File;Delete, etc) working. I was adding name and checking out the other commands, when I hit exit and I get the error message, "Bad File Name Or Number".

Inside my Exit command I have "Close #1 and Unload Me".

It doesn't do it all the time. Only if I do a lot of "playing" with the command buttons.

Any hints would be helpful!

Thanks in advance,

vbprogwb
(Bob)

Canceling An Exit When The X Button Is Click.
In the docs it says that the unload event is always run before the terminates.

However in my program I have a message box popup asking if the user wishes to save before exiting with a vbYesNoCanel and if the user hits cancel I have:

if query=vbcanel then Cancel = -1

In the docs it says making Cancel anything other than 0 will halt unload (and in theory terminate) this code only works when I hit the exit in my File menu.

So... that brings me back to the topic, how to I hate a close when the X button is pressed.

System Tray Right Click Exit
I just do not understand how to add a right clicking menu that allows options such as exit on the icon in the system tray. Umm, not too detailed, but can anyone help?

What Should I Set My Code If The User Click Cancel Button On The Commondialog?
how could I make my code robust when the user click the Cancel button on COMMONDIALOG ? thx a lot

sorry for ask simple questions, the search function on this forum could not return what I want, ^-^.

Regards

Yanli

Problem Exiting Applicatoin Using System Tray Icon (Right Click -> Exit)
Hi all,

I got problem with system tray icon in my application.

I used notify icon API to put icon in systemtray as someone closes the window. I also used double click event to show the window again and also use right mouse click event to show pupup menu which has options like : sign in, sign out, Exit(like Y! and MSN msngr).

Everything is working fine but when we close on Exit button with right clicking on systemtray icon it abnormally terminates the application showing "Don't send" button window in Windows XP.

I also want to say that if i click on the same menu option from form's menubar then it works fine. Also i use "End" method to close the application on that menu option.

if someone aware of this problem then please notify me.

Click OK In A Message Box
For my program, I am using a webbrowser control to navigate to certian pages. I have my webpage load and make sure there are no external links so that the user cannt naviate beyond my site. The problem is my hosting service pops up a prompt saying something like: "Click ok to stay on the current page, or cancle to win $1000000" (you know how those ads go.) But if a user clicks cancle, then they are brought to another page outside of my website and therefor can navigate as they please. Is there any way to automatically click OK so they dont have the chance to goto another page.

Click Message
Any api function to know if mouse has been clicked ?

Mouse click can be on a enabled or desabled window .

can getmessage be used for this . how ?

thanks

Have VB Auto Click A Message Box
Is there a way to have VB auto click a message box, or is there a way to have VB display a message box that goes away without having to click it?

Example:
Public Sub Goku()
MsgBox "The World"
Msgbox "The Planet"
End Sub

I would like for the message box to be displayed, but to go away without someone having to click it.


thanks,

Need To Click Message-box Automatically
Hi experts,
While trying to automate my tasks, I faced one challange:
I am running an application in batch mode, when it runs in admin mode, a msgbox pops up statating "Running in Administration mode".
Until user clicks on this msgbox, the application does not procees - even in batch mode. No GUI appears while running the application in batch mode.
Hence, I can not run batch scripts without having to physically wait (to click OK on the msgbox)

I want work around, so that I can handle 'clicking' on this msgbox automatically as and when it appears - as manytimes as I want.

Can anyone help me?
Regards
Dinesh

Why My Message Box Prompt Twice When I Click On No Button?
Hi..
i'm having problem with my message box..
when i click Yes button, it's ok..but when i click No button, the message box will prompt again until i click again the No button.
any idea?
this is the code,



Code:
Private Sub DataCombo_Change
Dim Msg As Integer

Msg = MsgBox("Are sure to select this category?", vbYesNo, "Confirmation")
If Msg = vbNo Then
DataCombo.Text = ""
Exit Sub
ElseIf Msg = vbYes Then
Exit Sub
End If
End Sub
thanx in advance..

List Box To Message Box And Command Click HELP
ive got a program where i have 1 command that puts random data into a list box how could i get the same command to put the data into the list box and into the message box and then make it seem as if a different button has been clicked??

Why My Message Box Prompt Twice When I Click On No Button?
Hi..
i'm having problem with my message box..
when i click Yes button, it's ok..but when i click No button, the message box will prompt again until i click again the No button.
any idea?
this is the code,

Code:
Private Sub DataCombo_Change
        Dim Msg As Integer
        
        Msg = MsgBox("Are sure to select this category?", vbYesNo, "Confirmation")
        If Msg = vbNo Then
            DataCombo.Text = ""
            Exit Sub
        ElseIf Msg = vbYes Then
            Exit Sub
        End If
End Sub


thanx in advance..;)

Display Message On Menu Click
How would I display a message when I click a menu button?

Cancel &"Do You Want To Save&" Message
I want to only allow people to save over this document if they hit a button on the worksheet. I did this with the beforesave event and had no problem. The only issue is if they make changes and then just go and close the document. It will ask if they want to save the changes. I tried setting the displayalerts to false but that doesn't seem to work. I also don't want the file to be read only because I want them to be able to save the new values in the document by clicking the button. How can I have it close without asking for a save?

Thanks!

Automatically Read And Click Message Boxes
Hello all,

I have a program I use on my system for doing electromagnetic simulations and I’m making a small utility program that will automatically configure it for me so I don’t have to be there all the time to monitor the simulations I’m doing. I want to make this a ‘smart’ program though and I was wondering if there was a way to monitor the simulator program for any message boxes, read the messages, and act accordingly. This is mainly for telling if an error in the program occurred so my program can restart the simulator. Also, is there a way to click the message boxes when they come up?

Thanks,
Jason O

Left Click Menu & Error Message
heya guys

I was wondering if it is possible to have a sub menu appear when the user left clickson a certain item. i have seen a few VB6 programs which have done it and as wondering if anyonecould tell me how to do it. Also then once i have done it how to remove it if i so wish.

Thank you in advance

Frosty

Listview Double Click Error Message
I have problem here.While I try doubleclick the listview when no list Item show in the listview, I got the error message like this "Object variable or with block variable not set" How to avoid this error meesage? When I do trapping error. the form pop up when I no listItem in the listview. How to avoid the form from pop up when I double click the the listview when no list Item show in the listview?


Code:
Private Sub ListView9_DblClick()
Form12.Text1.Text = frmSpatial.ListView9.SelectedItem.Text
Form12.Text2.Text = frmSpatial.ListView9.SelectedItem.SubItems(1)
'Form12.Text1.Text = frmSpatial.ListView9.ListItems(1).Text
Form12.Show
End Sub

Send A Double Click Message To The Tray Icon
Hi to all...and sorry for my English

I need to send a message of double-click to an application
in System Tray after his loading and after few second close it.

Any help for make this in VB6?

Thanks to all
NanniEvs

Send A Double Click Message To The Tray Icon
Hi to all...and sorry for my English

I need to send a message of double-click to an application
in System Tray after his loading and after few second, close it.

Any help for make this in VB6?

Thanks to all

Copyright © 2005-08 www.BigResource.com, All rights reserved