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




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




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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
------------------------------------------------------------------------------------------------------------------

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?

Common Dialog Box Click Problem
I am having a very strange occurence with my common dialog box, I just now discovered what is causing this problem.

I have a common dialog box that I use to get the path to certain picture files, when the box pops uo, it pops up right over my MSHFlexGrid I have on the form, and I figued out that when double click on a file to select it, it also sends that click through the dialog box and into the MSHFlexGrid, which triggers its click event.
when the MSHFlexGrid click event is triggered, it screws up the entire point of the dialog.

I guess what I would want do is find some way to trap that mouse click before it gets to the objects underneth it, or keep it with in the dialog box.
I have tried dissabling and then enabling the MSHFlexGrid, but the click gets through anyway, it gets enabled and the dialog goes away just in time for the click to get through.

how can I solve my problem?

Common Dialog Box: Do Something On Cancel
I allow the user to save a file using the Common Dialog box (Save As).
However I encounter a problem when trying to get the “Cancel” button to work, my goal is that when the user presses cancel, a Boolean key (Cancel) is set to true, if not it is left false.

Currently my code is:
On Error GoTo SaveErrHandler
ComDiaS.CancelError = True

ComDiaS.DialogTitle = "Save As"
ComDiaS.ShowSave
ComDiaS.FileName

SaveErrHandler:
Cancel = True

However this doesn’t work because no matter what, Cancel is always set to True.
The SaveErrHandler part is always run (seeing as it was placed before the “End Function”, but placing it outside gives an error (unknown SaveErrHandler).

Cancel On Common Dialog Box.
Hi,

when I select a file usinga common dialog box, to be entered into a listbox, if after selecting the file I click the cancel button, the file still is inserted into the listbox.
Is there a property or bit of code I can use to avoid that?

Cheers
df

Common Dialog On Cancel
Hey,
How can i know when the user clicked the Cancel button, in the Common Dialog control?
I set CancelError property to True and then what?

Common Dialog Box: Do Something On Cancel
I allow the user to save a file using the Common Dialog box (Save As).
However I encounter a problem when trying to get the “Cancel” button to work, my goal is that when the user presses cancel, a Boolean key (Cancel) is set to true, if not it is left false.

Currently my code is:
On Error GoTo SaveErrHandler
ComDiaS.CancelError = True

ComDiaS.DialogTitle = "Save As"
ComDiaS.ShowSave
ComDiaS.FileName

SaveErrHandler:
Cancel = True

However this doesn’t work because no matter what, Cancel is always set to True.
The SaveErrHandler part is always run (seeing as it was placed before the “End Function”, but placing it outside gives an error (unknown SaveErrHandler).

Common Dialog Cancel
I looked at the Common Dialog FAQ and it doesn't address this issue!

On using the ShowOpen property, how do you allow the cancel button to be used? As it is now, the file loads regardless of whether you click OK or CANCEL.

I thought .CancelError was what I needed but it doesn't seem to work as I expect.

Cancel On Common Dialog
Hi,

How do I check if somebody has pressed the cancel button on a common dialog box?

Thanx John



Edited by - johnminkjan on 11/2/2003 12:43:03 AM

Cancel Button In Common Dialog Api
how can i detect if the cancel button is pressed? i am using common dialog api.

Detect Cancel In Common Dialog
How can i detect if the user presses cancel on a common dialog open dialog?

Catching Cancel On A Common Dialog
I'm using the common dialog to create a colour picker, but when someone presses cancel, the code for black is returned. Is there a way to detect a cancel click?

Cancel Button In Common Dialog Box
friends,
i want to exit when the cancel button is pressed in commondialogbox.showPrinter. how to do that?

Common Dialog Box: Cancel Button
What code do i need to exit the sprocedure if the user clicks the cancel on the common dialog save box?

Cheers
ILMVbforums

Cancel Button On A Common Dialog
Hi Again,

How can I do a test to see if the cancel button on a common dialog has been pressed if it has been pressed msgbox say "hello" if I press the other button say "hi".

Thanks

Loftty

Common Dialog Cancel Error
using cdbFile.ShowOpen

When clicking the cancel button I get an error. I set CancelError to False.

How do you keep from getting the error?

Thanks again.

Common Dialog Handling A Cancel
I am working with several of the common dialog forms. My question is regarding the cancel. I am surprised that the dialogs don't set an attribute that the form was cancelled and believe I am missing something easy.

I have written the following to catch the error code but I am unsure if this is the best or even appropriate way to handle this.

I believe the Microsoft example has the code checking the filename after the execution of the dialog to see if a filename is returned. Unfortunately this doesn't seem to work if you are providing a default file for the dialog.


private Function OpenCommonDialog(sFileName as string) as string
'Work around to determine if the cancel button was clicked on the
' common dialog. The dialog doesn't set an attribute. You must
' catch the exception. Thanks Microsoft! Hence the seperate function
' for this purpose.

on error GoTo ErrorHandler:
'Perform the file write here
'prompt for the file location.
dlgBrowseFile.Flags = cdlOFNOverwritePrompt & cdlOFNPathMustExist
dlgBrowseFile.InitDir = sFileName
dlgBrowseFile.Filter = "All Text (*.txt)|*.txt"
dlgBrowseFile.DefaultExt = "REV"
dlgBrowseFile.CancelError = true
dlgBrowseFile.ShowSave
sFileName = dlgBrowseFile.filename

End1:
OpenCommonDialog = sFileName
Exit Function

ErrorHandler:
sFileName = ""
resume End1:
End Function




Thanks EveryOne
All comments welcome...
(I'll do anything to avoid the goto statement!)

Problem With Common Dialog And Cancel Button
Hi,

sorry, i know this has been asked a lot of times on this board, but i've tried all the solutions and nothing works for me.

Here is my code:


Code:
Private Sub Command1_Click()

On Error GoTo cancel_error

CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter

Printer.PaintPicture LoadPicture(App.Path & "
eportlogo_report.bmp"), 9000, 750
Printer.PaintPicture Picture2.Image, 1500, 2000, , , , , , , vbSrcCopy
Printer.EndDoc
Exit Sub

cancel_error:

Exit Sub

End Sub
My problem is that when the printer dialog box open and i click on cancel button it doesn't reach the cancel_error (error threatment) line but i get an error messagebox saying: "error 32755 at runtime, cancel has been selected" on line CommonDialog1.ShowPrinter.

I just want to exit sub when i click on cancel.

what can i do?

Thanks in advance!

Common Dialog ShowSave Cancel Error
Why doesn't this work? When I press the "Cancel" button, I get run-time error 32755 "Cancel was Selected". I have an error handler and I have the cancelerror property set to true. (I have also set the property to true in the properties button of the common dialog).

Private Sub mnuExcelExport_Click()
Dim export As Boolean
Dim strFileName As String

On Error GoTo Cancel_Error
With CommonDialog1
strFileName = CJobCost.JobName & Trim(" Job Costs.xls")
.Filter = "Excel (*.xls)|*.xls"
.FileName = strFileName
.CancelError = True
.ShowSave
If .FileName <> "" Then
export = spreadItems.ExportExcelBook(.FileName, "")
End If
End With
Exit Sub
Cancel_Error:
If Err.Number <> cdlCancel Then
MsgBox Err.Description
End If
End Sub

Common Dialog Cancel Question [solved Again]
How do I exit my sub if my user clicks cancel on the common dialog box?

I used :
VB Code:
if cd.cancel = true thenexit subend if


but got a invalid use of property error..

Common Dialog Cancel Pressed (RESOLVED)
Hi All,

Why is this not going into my error code when I press the cancel button on the common dialog?


VB Code:
If findFile = True ThentxtSaveAsDirectory.Text = ""    Screen.MousePointer = vbArrow    On Error GoTo saveAsError        With cdSaveas            .DialogTitle = "Locate Qwest database"            .Filter = "Access database (*.mdb*)|*.mdb*"            .fileName = "data.mdb"            .InitDir = tempStr            .ShowSave            .CancelError = True        End With                OpenDialogTest = True        Open_Dialog_Backup (OpenDialogTest)         saveAsError:           End If


Thanks

Loftty

Cancel Clicked In Common Dialog In Excel
Is there anyway to test if the user has clicked the cancel button when prompted with a save common dialog in excel...

i would check to see if the file path is empty... but i am giving the user a default save title.. any ideas?

Common Dialog Cancel Error Trap?
If the user hits Cancel on the Common Dialog box... the way my program i set up now the code keeps running and i get to an error because no file has been selected.

If they hit cancel, I want to return to the previous state... basically.. where the main form is being displayed and everything is idle. I hope i've explained so you understand.

Thanks,

Eric

Detect Cancel Button Using Common Dialog Api
how can i detect if the cancel button is pressed? i am using common dialog api.



Edited by - Red0ut on 6/25/2004 8:53:26 AM

Common Dialog Box Cancel Button To Close Program
I'm using a common dialog box, to grab the path of a file to open. But if the user clicks cancel i want the program to close. How do i do this?

Cancel Button Not Working Properly While Using Common Dialog
hi,

I m using VB macros in the Microsoft Project Plan to convert the plan into xml using the common dialog.
Its working fine for Save the MPP into xml format.

However once i save it and then try to use the Save as menu, it captures the name of the file which i saved earlier and even if i cancel the dialog box, the file is saved using that name.

im attaching the code for reference:
DialogForm.CommonDialog1.Filter = "All Xml (*.xml)"
DialogForm.CommonDialog1.ShowSave
If (DialogForm.CommonDialog1.fileName = "") Then

End If
If (DialogForm.CommonDialog1.fileName <> "") Then
xmlFileName = DialogForm.CommonDialog1.fileName + ".xml"

anybody has any idea, why the problem is coming.

Common Dialog: When Cancel Is Pressed, Error Is Generated
How do I trap this error??? I dont want it to show a run time error and shut down the program!

Common Dialog Load List Cancel Error
When someone clicks "Load List" on my program, it opens the load dialog but if they click cancel it keeps adding blank items to the list and freezes. Here is the code

List1.Clear
CommonDialog1.DialogTitle = "[ListBox Functions 2001] Load"
CommonDialog1.InitDir = App.Path
CommonDialog1.Flags = &H4
CommonDialog1.Filter = "list files (*.txt)|*.txt|all files or custom(*.*)|*.*"
CommonDialog1.ShowOpen
Call xLoadList(CommonDialog1.FileName, List1)
List1.ListIndex = 0

Sorry, dont know how to post as VB code..

Trouble With The Cancel Button In The Common Dialog Control
whenever i test it and click cancel, it crashes me proggy

then when i use "On Error Resume Next" it crashes and times out my proggy, and i have to alt ctrl del to close it

could you suggest what i could be missing from this?

Realizing Cancel Button In Common Dialog Boxes
How can you notice if the cancel button was pressed using common dialog boxes?

Oh and I am going to throw in a second question. what printer flags should i use for standard printing? And to print a textbox it would be :
Code:Printer.Print text1.text correct?

Detecting Clicking The Cancel Button Using Common Dialog Controls
Hi,

I want to exit a sub if a user hits the cancel button in a save/open dialog. How do I do it????

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]

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.

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?

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

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.

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

List Box Click / Dynamic Change Difference
hi all,

im having a problem with one of my programs...

i need to be able to tell the diffrerence between and actual click of a list box changing the ListIndex and if the ListIndex is changed in the code...

at the moment what happens is if i change the ListIndex in the code, the "Private Sub List_Click()" is executed, and i need to prevent this.

if anyone can offer assistance, please do, it would be much appreciated.

kind regards and thanks for time / consideration,

Mojoinst

Getting A Button Click From A Custom Dialog Box
I hope that I can describe what I am trying to do.

I am using VB.NET

First this is a database application that has users entering data from paper forms. The data forms have a table class that handles the access to/from the db. When the data form is opened it instantiats(sp?) a table class obj passing a refference of the form to the class. This refference is used when opening a dialog box from the class. What I want to do is get the button click event from the dialog box and handle it in the class. Here is the code that I have so far for this.


Code:
Dim frmChanges As New frmVerifyChange()
frmChanges.txtChanges.Text = _DDE.strChangeHistory
frmChanges.ShowDialog(_frmParent)

:confused:
'WHAT DO I NEED TO PUT HERE TO RECIEVE THE BUTTON CLICK?
'THE BUTTON COULD BE cmdYes or cmdNo

frmChanges.Close()
Thank you for your help,
kaytrim

Click OK Or Press Enter On A Dialog Box
I am using USER32 to SetForegroundWindow to make it the active window and SendMessage to do a keydown of Enter.  I am able to see that I have the handle on it, but the "ENTER" is not working!!!  Any idea's???

Please help!!
THANKS!

Open Dialog And Not Click On Main Form?
OK I want a program to open up a dialog when I click a button. Then when the dialog is open I want it to be the only thing that can be used until it is closed. Like you know how if there is an error message on your computer you cant click anything in the background until you close the error message. Like that. I know how to make it open and all that just how can you get it to not allow the clicking and input anywhere but in the Dialog. Thanks in advance for any help on this topic.

DataGrid - Click On A Row And Access Detail Dialog
Is it possible to enable the user to click on a row in the ADO DataGrid control and then access another dialog box (either via double click or a command button on the form) and enter/save data into this seperate dialog? The data entered here would essentially be detail data for the data grid. If so, does anyone have any sample code or ideas on this?

Thanks in advance for any info anyone may have.

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