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




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




View Complete Forum Thread with Replies

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

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..

How To Add Common Dialog Showsave ?
Hay friends,,,i want to add a funcationality that user will be able to save spreadsheet anywhere he/she wants... here is the whole code....i just donno how to add Common Dialog Showsave...is anybudy have any idea how to add Common Dialog showsave in the following...???replayes with the answers will be highly appericiate... thanz a lot in advance





Private Sub Export()
'EXPORT TO EXCEL PROJECT DEFINITION
On Error GoTo Err_Handler
'Dim dte As Date
'create the new directory to store the project workbooks
Dim strDate As String
strDate = Format(Now, "yyyy_mmm_dd")
Dim intC As Integer
'if the directory has already been created, an error will be thrown
'and caught
Dim strDirPath As String

'++IMPORTANT++++THIS COMMAND CAN BE REMOVED ONCE FOLLOWING DETERMINED++
    
    '=======Exit Sub

'**********THE FOLLOWING DIRECTORY NEEDS TO BE DETERMINED*************
strDirPath = "ExcelWorkbooks" & strDate & "_" & strType
'MkDir App.Path & strDirPath

'for testing change app.path, for example, to "C:"
'********************************************************************

If blnError = True Then
    blnError = False
    Exit Sub
End If

Dim strDir As String
Dim strProjName As String
Dim sqlDetail As String
Dim rstDetail As ADODB.Recordset
Dim intStep As Integer
Dim intIncrement As Integer
Dim intI As Integer
Dim strSQL As String
Dim rsAllocation As ADODB.Recordset

''xl must be declared as Object at the Form-level declarations
'Set xl = CreateObject("Excel.Application")


If intExportType = 1 Then 'no filtering required
    sqlDetail = "Select distinct * From QRY_Export_Master"
Else
    sqlDetail = "Select distinct * From QRY_Export_Master where " & strClause
End If
Set rstDetail = New ADODB.Recordset
'If rstDetail.State = adStateOpen Then
' MsgBox "Open"
'End If

rstDetail.Open sqlDetail, deWP.conWP, adOpenKeyset, adLockOptimistic




If rstDetail.EOF And rstDetail.BOF Then
  Me.MousePointer = 0
  MsgBox "Nothing to report at this time.", vbInformation
  rstDetail.Close
  Set rstDetail = Nothing
  Exit Sub
End If
intStep = rstDetail.RecordCount
'xl must be declared as Object at the Form-level declarations
'Set xl = CreateObject("Excel.Application")
Set xl = New Excel.Application
xl.Visible = True
'FILL SPREADSHEETS
'Do While Not rstDetail.EOF
Do While rstDetail.EOF = False


'fill counter bar
'Select Case intIncrement
'Case intStep * 0.1 = intIncrement
'Me.Text1(0).BackColor = vbRed
'Case intStep * 0.2 = intIncrement
'Me.Text1(1).BackColor = vbRed
'Case intStep * 0.3 = intIncrement
'Me.Text1(2).BackColor = vbRed
'Case intStep * 0.4 = intIncrement
'Me.Text1(3).BackColor = vbRed
'Case intStep * 0.5 = intIncrement
'Me.Text1(4).BackColor = vbRed
'Case intStep * 0.6 = intIncrement
'Me.Text1(5).BackColor = vbRed
'Case intStep * 0.7 = intIncrement
'Me.Text1(6).BackColor = vbRed
'Case intStep * 0.8 = intIncrement
'Me.Text1(7).BackColor = vbRed
'Case intStep * 0.9 = intIncrement
'Me.Text1(8).BackColor = vbRed
'Case intStep * 1 = intIncrement
'Me.Text1(9).BackColor = vbRed
'End Select
'intIncrement = intIncrement + 1
'
    
    'xl.Workbooks.Close App.Path & "ExcelWorkbooksTEST_MasterExport_WPS.xls"
    'Set xlWb = xl.Workbooks.Open(App.Path & "ExcelWorkbooksMasterExport_WPS.xls")
     Set xlWb = xl.Workbooks.Open("C:ExcelWorkbooksMasterExport_WPS.xls")
    
    'populate the Excel sheet
    Dim RowCnt, FieldCnt, ColCnt As Integer
    ''''''''''''''''''''''''''''''''''
    'FILL PROJECT SECTION
    'MsgBox rstDetail.Fields("ProjectID").Value
 
    xl.Range("ProjectID").Select
    'xl.Range("ProjectID").Format
    xl.ActiveCell.Value = CInt(rstDetail.Fields("ProjectID").Value)

    xl.Range("ProjectDescription").Select
    xl.ActiveCell.Value = rstDetail.Fields("ProjectDescription").Value
    
    xl.Range("A3").Select
    xl.ActiveCell.Value = "This report was exported as of " & strDate
   
    
    xl.Range("ProjectPlanYear").Select
    xl.ActiveCell.Value = rstDetail.Fields("ProjectPlanYear").Value
    xl.Range("WorkPlanApproval").Select
    xl.ActiveCell.Value = rstDetail.Fields("WorkPlanApproval").Value
    xl.Range("MasterProjectID").Select
    xl.ActiveCell.Value = rstDetail.Fields("MasterProjectID").Value
    xl.Range("ProjectStateID").Select
    xl.ActiveCell.Value = rstDetail.Fields("ProjectStateID").Value
    xl.Range("ProjectTypeID").Select
    xl.ActiveCell.Value = rstDetail.Fields("ProjectTypeID").Value
    xl.Range("SizeScopeID").Select
    xl.ActiveCell.Value = rstDetail.Fields("SizeScopeID").Value
    xl.Range("PriorityID").Select
    xl.ActiveCell.Value = rstDetail.Fields("ProjectPriorityID").Value
    xl.Range("ImportanceID").Select
    xl.ActiveCell.Value = rstDetail.Fields("ImportanceID").Value
    'NOT CURRENTLY USED
    'xl.Range("OtherRankID").Select
    'ActiveCell.Value = rstDetail.Fields("OtherRankID").Value
    xl.Range("GateID").Select
    xl.ActiveCell.Value = rstDetail.Fields("GateID").Value
    xl.Range("PhaseID").Select
    xl.ActiveCell.Value = rstDetail.Fields("PhaseID").Value
    xl.Range("EstimatedValue").Select
    xl.ActiveCell.Value = rstDetail.Fields("EstimatedValue").Value
    xl.Range("InitiativeFundingApprovalID").Select
    xl.ActiveCell.Value = rstDetail.Fields("InitiativeFundingApprovalID").Value
    xl.Range("BudgetSubmissionTypeID").Select
    xl.ActiveCell.Value = rstDetail.Fields("BudgetSubmissionTypeID").Value
    'xl.Range("ProgramFunctionLink").Select
    'ActiveCell.Value = rstDetail.Fields("ProgramFunctionLink").Value
    xl.Range("AllocatedYear").Select
    xl.ActiveCell.Value = intYr
    'dates
    
    xl.Range("TargetStartDate").Select
    If CDate(rstDetail.Fields("TargetStartDate").Value) <> CDate(dte) And Not IsNull(rstDetail.Fields("TargetStartDate").Value) Then
    xl.ActiveCell.Value = Format(rstDetail.Fields("TargetStartDate").Value, "yyyy/mm/dd")
    End If
    
    xl.Range("TargetCompleteDate").Select
    If CDate(rstDetail.Fields("TargetCompleteDate").Value) <> CDate(dte) And Not IsNull(rstDetail.Fields("TargetCompleteDate").Value) Then
        xl.ActiveCell.Value = Format(rstDetail.Fields("TargetCompleteDate").Value, "yyyy/mm/dd")
    End If
    
    xl.Range("StartDate").Select
    If CDate(rstDetail.Fields("StartDate").Value) <> CDate(dte) And rstDetail.Fields("StartDate").Value <> vbNull Then
        xl.ActiveCell.Value = rstDetail.Fields("StartDate").Value
    End If
    
    
    xl.Range("CompleteDate").Select
    If CDate(rstDetail.Fields("CompleteDate").Value) <> CDate(dte) And Not IsNull(rstDetail.Fields("CompleteDate").Value) Then
    xl.ActiveCell.Value = rstDetail.Fields("CompleteDate").Value
    End If
    
    
    Me.MousePointer = 0
    Dim strProjectName As String
    strProjectName = rstDetail.Fields("ProjectDescription").Value
    'replace illegal characters in filename
    strProjectName = Replace(strProjectName, "/", "_")
    strProjectName = Replace(strProjectName, "*", "_")
    strProjectName = Replace(strProjectName, "+", "_")
    strProjectName = Replace(strProjectName, "=", "_")
    strProjectName = Replace(strProjectName, "%", "_")
    strProjectName = Replace(strProjectName, "$", "_")
    strProjectName = Replace(strProjectName, "#", "_")
    strProjectName = Replace(strProjectName, ":", "_")
    strProjectName = Replace(strProjectName, "?", "_")
    strProjectName = Replace(strProjectName, "]", "_")
    strProjectName = Replace(strProjectName, "[", "_")
    strProjectName = Replace(strProjectName, "<", "_")
    strProjectName = Replace(strProjectName, ">", "_")
    strProjectName = Replace(strProjectName, "&", " and ")
    strProjectName = Replace(strProjectName, ",", "_")
    'add extension for confused project names with periods :^.
    If InStr(1, strProjectName, ".") > 0 Then
        strProjectName = strProjectName & ".xls"
    End If
    
    'add the allocations
    RowCnt = 4
    ColCnt = 6
    Dim MntCnt As Integer
    MntCnt = 11
    Set rsAllocation = New ADODB.Recordset
    strSQL = "Select * FROM QRY_EXPORT_Allocations_Sorted WHERE [Project ID] =" & rstDetail("ProjectID").Value & " AND AllocateYear = " & intYr & " order by ITResourceRoleID"
    rsAllocation.Open strSQL, deWP.conWP, adOpenForwardOnly, adLockOptimistic
    
    With rsAllocation
    Do While Not .EOF
        xl.Cells(RowCnt, ColCnt).Value = .Fields("ITResourceID").Value
        xl.Cells(RowCnt, ColCnt + 2).Value = .Fields("ITResourceRoleID").Value
        'add in days per month
        xl.Cells(RowCnt, MntCnt).Value = .Fields("Jan").Value
        xl.Cells(RowCnt, MntCnt + 1).Value = .Fields("Feb").Value
        xl.Cells(RowCnt, MntCnt + 2).Value = .Fields("Mar").Value
        xl.Cells(RowCnt, MntCnt + 3).Value = .Fields("Apr").Value
        xl.Cells(RowCnt, MntCnt + 4).Value = .Fields("May").Value
        xl.Cells(RowCnt, MntCnt + 5).Value = .Fields("Jun").Value
        xl.Cells(RowCnt, MntCnt + 6).Value = .Fields("Jul").Value
        xl.Cells(RowCnt, MntCnt + 7).Value = .Fields("Aug").Value
        xl.Cells(RowCnt, MntCnt + 8).Value = .Fields("Sep").Value
        xl.Cells(RowCnt, MntCnt + 9).Value = .Fields("Oct").Value
        xl.Cells(RowCnt, MntCnt + 10).Value = .Fields("Nov").Value
        xl.Cells(RowCnt, MntCnt + 11).Value = .Fields("Dec").Value
        'define next row
        RowCnt = RowCnt + 1
        .MoveNext
    Loop
    .Close
    End With
    
    'add budget figurs
    RowCnt = 26
    ColCnt = 1
    Dim rsBudget As New ADODB.Recordset
    strSQL = "Select * From QRY_EXPORT_ProjectMasterWithBudgets WHERE PROJECTID=" & rstDetail("ProjectID").Value
    rsBudget.Open strSQL, deWP.conWP, adOpenForwardOnly, adLockReadOnly
    With rsBudget
    Do While Not .EOF
        xl.Cells(RowCnt, ColCnt).Value = .Fields("CapitalProjectNo").Value
        xl.Cells(RowCnt, ColCnt + 1).Value = .Fields("ApprovedBudget").Value
        xl.Cells(RowCnt, ColCnt + 2).Value = .Fields("YTDSpentCommitted").Value
        xl.Cells(RowCnt, ColCnt + 3).Value = .Fields("MoniesReturned").Value
        RowCnt = RowCnt + 1
        .MoveNext
    Loop
    .Close
    End With
    
    'add cash flow figures
    Dim iint As Integer
    Dim rsCash As New ADODB.Recordset
    strSQL = "Select * from qry_Export_CashFlow_Totals WHERE PROJECTID=" & rstDetail("ProjectID").Value & " AND CashFlowYear = " & intYr & " order by QTR"
    rsCash.Open strSQL, deWP.conWP, adOpenForwardOnly, adLockReadOnly
    'iint = rsCash.RecordCount
    If rsCash.EOF Or rsCash.BOF Then
    Else
    'only need one value
    xl.Range("TotalCashFlow").Select
    xl.ActiveCell.Value = rsCash.Fields("TotalCashFlow").Value
    xl.Range("Remaining").Select
    xl.ActiveCell.Value = rsCash.Fields("Remaining").Value

    With rsCash
    .MoveFirst
    Do While Not .EOF
    'quarters LOOP THRU THE MULTIPLE RECORDS AND CAPTURE THE QTR REQ'D IN THE RIGHT CELL
    Select Case .Fields("QTR").Value
    
        Case "Q1"
            xl.Range("Quarter1").Select
            xl.ActiveCell.Value = .Fields("SumOfAmount").Value
        Case "Q2"
            xl.Range("Quarter2").Select
            xl.ActiveCell.Value = .Fields("SumOfAmount").Value
        Case "Q3"
            xl.Range("Quarter3").Select
            xl.ActiveCell.Value = .Fields("SumOfAmount").Value
        Case "Q4"
            xl.Range("Quarter4").Select
            xl.ActiveCell.Value = .Fields("SumOfAmount").Value
        
    End Select
    
    .MoveNext
    Loop
    End With
    
    End If
    rsCash.Close
    
    
    'save and close the file
    'strDir = App.Path & strDirPath & "Project_" & CStr(rstDetail.Fields("ProjectID").Value) & "_" & strProjectName
    strDir = "C:" & strDirPath & "Project_" & CStr(rstDetail.Fields("ProjectID").Value) & "_" & strProjectName
    MsgBox strDir
    
    xlWb.SaveAs strDir
    'cdOpen.ShowSave
    'print after saving to capture the workbook filename
    'I SHOULD ADD cdOpen here ================================
     
   
   
   
    
    If ckPrint(0).Value = vbChecked Then
    
        xl.ActiveSheet.PrintOut
    End If
    For intC = 1 To 1000
    Next intC
   
    'xlwb.Close
    xlWb.Close SaveChanges:=False
    Set xlWb = Nothing
    


    rstDetail.MoveNext

'get next project id
Loop



   
'xl.Visible = True
'close recordset

rstDetail.Close
Set rstDetail = Nothing
'xl.Quit
'Set xl = Nothing
'xlwb.Close
'Set xlwb = Nothing
'
'Set xl = Nothing



'xlwb.Close SaveChanges:=False
'Set xlwb = Nothing
'xl.Visible = False
 xl.Application.Quit

xl.Quit
Set xl = Nothing




Set rsAllocation = Nothing
Set rsBudget = Nothing
Set rsCash = Nothing
For intI = 1 To 1000
Next intI

'For intStep = 0 To 9
'Me.Text1(intStep).BackColor = vbWhite
'
'Next

Exit Sub



Err_Handler:

Select Case Err.Number

Case 3265 'null values
    Resume Next
Case 75 'dir was already created
    'Set xl = Nothing
    MsgBox "The specified directory with today's date already exists."
    blnError = True
    Resume Next
Case 1004
    Resume Next
Case Else
    'release Excel references
    If rstDetail.State = adStateOpen Then
        rstDetail.Close
    End If
    xl.Quit
    Set xl = Nothing
     Set xlWb = Nothing
     Set rsAllocation = Nothing
     Set rsBudget = Nothing
     Set rsCash = Nothing
     
     
     Me.MousePointer = 0
     MsgBox "Error in Export(): " & Chr(13) & Err.Description & " " & Err.Number, vbInformation
End Select




End Sub

Problems With Common Dialog ShowSave
In my application I use the following code to save a report. But when I press Cancel, the whole application shuts down. I tried to change the CancelError value, but it doesnt help. even worse, when I change it, I press Save and again the whole application shuts down. Very wierd.
I used an event viewer to see what's going on and according to the event viewer the application is trying to write data to a memory space it is not allowed to save on.
Tried to use the errorhandler, catching the error 0 and 32755 but it still doesnt work good.
Any suggestions? Maybe some ideas how I could handle the whole saving and cancelling process myself?
I'm a bit desperate.

[start of code]

Private Sub cmdSaveRapport_Click()
On Error GoTo fout
cmdSave.Filter = "BSDMan Rapporten (*.xls)|*.xls"
cmdSave.ShowSave

Dim xlWorkbook As Excel.Workbook
Set xlWorkbook = OLEDiverseCalls.object
Dim xlSheet As Excel.Worksheet

xlWorkbook.Windows(1).Visible = True

xlWorkbook.SaveAs cmdSave.FileName
xlWorkbook.Close

Set xlWorkbook = Nothing

exit sub
fout:
errorHandling
End Sub

[end of code]

Common Dialog - .ShowSave Thing.. *slvd*
hey ya:


VB Code:
' ------------------------------------------------------------' Save Log File Sub Routine' ------------------------------------------------------------ Private Sub Save_File()On Error GoTo ErrHandle:Dim FileName As String, lFile As StringDim NewDate As String, NewTime As String NewDate = Replace(Date, "/", "-")NewTime = Replace(Time, ":", "-")     CommDia1.Filter = "Text Files (*.txt)|*.txt" & _                 "|All Files (*.*)|*.*"    CommDia1.InitDir = App.Path & "Logs"    CommDia1.FileName = App.Path & "Logs" & NewDate & " - " & NewTime & ".txt"    CommDia1.ShowSave    FileName = CommDia1.FileName    If Len(FileName) > 0 Then        lFile = FreeFile        Open FileName For Output As #lFile            Print #lFile, txtLogWindow.Text        Close #lFile    End IfExit Sub ErrHandle:    If Err.Number = "32755" Then        'It's a Cancel Error, Just Ignore it    Else        MsgBox "Error: " & Err.Description, vbOKOnly, "Error # " & Err.Number        Err.Clear    End IfEnd Sub


I have this code to save my log windows etc,

Its all working, ETC

If a filename already exsists for my file, I Wanna show the "This file already exsists" msgbox, asking to replace, cancel, etc,

How do i add dat to the CommDia1 control?

Tnx

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 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!)

"Concept Problem" With Common Dialog ShowSave
VB 6 Enterprise, OS=Widows Pro

Problem Area: Common Dialog Control using the Save Window
I thought on a "ShowSave", the CommonDialog.Filename specifies the path and name of the file to be saved. Looking at the code below, I commented the "DialogControl.FileName" statement, ran this routine and chose the "ALL File" filter. The routine would not save any file.

Using a CommonDialog ShowSave, how and where do you specify the file that is to be saved? I know, in the "Save In" box is where you want the file to be saved to.

If you want to run this code, all you need is a form with a command button on it and a Common Dialog Control.

CommonDialog Control Name = DialogControl

Code:
Private Sub Command1_Click()
Dim CancelMe As Boolean
CancelMe = False
' Set CancelError is True
DialogControl.CancelError = True
On Error GoTo ErrHandler
' Set flags
DialogControl.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt
' Set filters
DialogControl.Filter = "All Files (*.*)|*.*|mdb Files" & _
" (*.mdb)|*.mdb"
' Specify default filter
DialogControl.FilterIndex = 2
' Display the Save dialog box
'DialogControl.FileName = "c:orion racking racking.mdb" 'file TO BE copied
DialogControl.ShowSave
Exit Sub

ErrHandler:
If Err.Number = 32755 Then CancelMe = True
Exit Sub
End Sub

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 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?

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.

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????

Problem With Cancel Button In Showsave
Here's my code and when I hit cancel, it's generating an error instead of exiting my sub. What am I doing wrong? Thanks.

With frmTest.cmnDialog1
.Filter = "Access (*.mdb)|*.mdb"
.Flags = &H2
.CancelError = True
.ShowSave
If Err.Number = 32755 Then
Exit Sub
End If
dbToPath = .FileName
End With

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

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 Error
When I try to insert a common dialog in to my form, I get an error saying I don't have permission. A message box comes up and when I click help, the information provides a help error code 429. Any ideas why I can't use the common dialog control?

Matt

Common Dialog Error
I have one app that use commondialog control, it works fine, but when i click cancel, asn error occurs because the app is waiting for the filename. How can i capture the click in cancel button to avoid this error?

if you want to hit the stars,shoot to the sky.

Common Dialog Error?
I am using the following code to try and get an open box to appear, however an run time error comes up saying object required???? Any ideas

Private Sub cmdSave_Click()
' Set CancelError is True
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' Set flags
CommonDialog1.Flags = cdlOFNHideReadOnly
' Set filters
CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files" & _
"(*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' Specify default filter
CommonDialog1.FilterIndex = 2
' Display the Open dialog box
CommonDialog1.ShowOpen
' Display name of selected file
MsgBox CommonDialog1.FileName
Exit Sub

ErrHandler:
'User pressed the Cancel button
Exit Sub
End Sub

Common Dialog Error
When I go to use the Common Dialog to select a font, it tells me that no fonts are installed...I have hundreds of fonts.

What's wrong?

Error With The Common Dialog
Hi I'm trying to change the font in a Rich Text Box. So when I run a line like this

CommonDialog1.Action = 4

I get A msgBox Saying
"There are no fonts installed. Open the fonts folder from the Control Panel to install fonts."
then I press OK and it gives me a Run-time error '24574' no fonts exist Error, so I go to the fonts folder and there are plenty
of fonts.

Does any body have a solution or alternative?

Thanks all

Common Dialog Error
lads,

in vb6 i show the print setup using a common dialog

my proplem is do when i create an exe i get
a error saying the comdlg32.ocx is not registered on some pc's

do i need to register the ocx on every machine or is there a quick and
clean
way around this
without creating a vb package

or can u show the print setup using something else

Thanks In Advance

Mick

HELP Common Dialog Error!
i am attempting to add a media feature to my program, but i keep getting a weird error
when i click on the command button cmdOpenMedia. it goes:

    Run-time error '32765':

    The common dialog function failed during initialization. This error often
    occurs when there is insuffient memory available

What does this problem mean? And how can i fix it w/o making any sacrifices to my code?
(i have almost no doubt that it is a problem with my 968-character CommonDialog filter,
which, for the record, put on just one line of code)

Code:Private Sub cmdOpenMedia_Click()
    Dim aFileName As String, aMedia As IWMPMedia
    CmnDlg.DialogTitle = "Open Media File"
    CmnDlg.Filter = "Media files (all types)/*.asf;*.asx;*.wax;*.wm;*.wma;*.wmd;*.wmp;*.wmv;*.wmx;*.wpl;*.wvx;*.avi;*.wav;*.mpeg;*.mpg;*.m1v;*.mp2;*.mpa;*.mpe;*.mp2v;*.mpv2;*.aif;*.aifc;*.aiff;*.mid;*.midi;*.rmi;*.cda;*.au;*.snd;*.mp3;*.m3u;*.vob;*.swf/Windows Media audio and video files (*.asf; *.asx; *.wax; *.wm; *.wma; *.wmd; *.wmp; *.wmv; *.wmx; *.wpl; *.wvx)/*.asf;*.asx;*.wax;*.wm;*.wma;*.wmd;*.wmp;*.wmv;*.wmx;*.wpl;*.wvx/Windows audio and video files (*.avi; *.wav)/*.avi;*.wav/Moving Picture Experts Group (MPEG) (*.mpeg; *.mpg; *.m1v; *.mp2; *.mpa; *.mpe; *.mp2v; *.mpv2)/*.mpeg;*.mpg;*.m1v;*.mp2;*.mpa;*.mpe;*.mp2v;*.mpv2/Audio Interchange File Format (AIFF) (*.aif; *.aifc; *.aiff)/*.aif;*.aifc;*.aiff/Musical Instrument Digital Interface (MIDI) (*.mid; *.midi; *.rmi)/*.mid;*.midi;*.rmi/Music CD Playback (CD audio) (*.cda)/*.cda/AU (UNIX) (*.au; *.snd)/*.au;*.snd/MP3 (*.mp3; *.m3u)/*.mp3;*.m3u/DVD video (*.vob)/*.vob/Macromedia Flash (*.swf)/*.swf/"
    CmnDlg.ShowOpen
    aFileName = CmnDlg.FileName
    With WindowsMediaPlayer
        .currentPlaylist.Clear
        Set aMedia = .newMedia(aFileName)
        .currentPlaylist.appendItem aMedia
        .Controls.play
    End With
End Sub

thanx

<Edit> You have to edit your *first* post for the title change to be visible in the topic list </Edit>

If you do not use correct grammar, people will lose respect for you, and they will burn down your house.
    --Dave Barry



Edited by - Metallisoft on 1/23/2005 6:09:24 PM

Problem With Dialog Box .ShowSave Method--
Okay, here's what I'm doing... I have a child form inside an MDI parent form. The MDI parent has a toolbar that includes Save and Open (new).. nothing unusual there.

I've caused some really wierd behavior doing this: Opening a file, then closing it so that there is NO child form loaded in the MDI container form. Now...

I open a new file-- that is to say, I load a new 'blank' child form that contains a rich text box-- it is appropriately titled "Document #2" (or, depends on how many new document [child] windows I have opened) and I can then proceed to type information (or not) into the rtf control on the form.

Next, I click on the save button of the MDI form's toolbar, which goes to a Select Case statement inside the code window of the MDI form. It properly drops down to the correct procedure call (mnuFileSave_Click) which then calls on the frmChild.FileSaved procedure.

So far, so good. (I've stepped through this so many times I could type the lines of code with my eyes closed... but still no answer to my conundrum!)

Next, the FileSaved procedure in the frmChild code block executes:

Code:
Public Sub FileSaved()
    'save the contents of the RTF control as a file and leave the file open
    
    Dim strNewFile As String
    Dim intFileType As Integer
    Dim intNameLen, intPointer As Integer
    
    'CancelError property is set to True in design
    On Error GoTo ErrorHandler:
    
    dlgGeneral.ShowSave
    'make sure save is only allowed to either .rtf format or
    '.txt format
    dlgGeneral.Filter = "Text (*.txt)/*.txt/Rich Text Format (*.rtf)/*.rtf"
    dlgGeneral.FilterIndex = 1

    If dlgGeneral.FilterIndex = 1 Then
        intFileType = 1
    Else
        intFileType = 0
    End If
        
    'now save the file with the file name and extension type
    strNewFile = dlgGeneral.FileName
    rtfDocumentWindow.SaveFile strNewFile, intFileType
 

However!!!! When the line that reads dlgGeneral.ShowSave is reached, I get the Open dialog box instead!!!! When I step through this using the debugger, this line triggers the Form_Load event of the child form, though to my way of thinking, it should do nothing more than open a Save As dialog box!

This never happens when another child form (saved or not, new or loaded with a previously existing tex file) is already present (but not active) in the parent MDI form, but happens every time there is no current (loaded) child form in the parent MDI.

So, can anyone tell me why the .ShowSave method would do this to me when I have (an as-yet-unsaved) file open (i.e. -- one child form that has been loaded and initialized)???

Once I get the Open dialog box and click cancel, THEN I get the Save As dialog box... but when I click cancel (or save) and return to the program, there is now a blank, untitled child form in addition to the one I saved (or didn't.)

Am I making much sense? Have I gone into too much detail? Not enough?

Bottom line is this: when no other child form is loaded into the MDI parent form, and I open one by loading a file into the rtf control via dialog box, I can't save it without generating a blank, untitled child form. This peculiar behavior does not occur if I have an already-open child form in the MDI parent form. In that case, the program works just fine.


 "There's time enough to sleep when you're dead!"

Using The ShowSave Dialog Encoding Option
When saving text files with Notepad, the Encoding dropdown list always appears, but not when using the Common Dialog Controls. Is there some way to use it, and could it be used to automatically save files with different encodings rather than ANSI?

Below is a screenshot of the option I mean:

Error After Usin Common Dialog
Hi!
After pressing a button with this code

Code:
Private Sub Command1_Click()
On Error GoTo cancel_error
cd.Filter = "Documentos Word|*.doc|Todos los Documentos|*.*"
cd.ShowOpen
texto = cd.filename
MsgBox cd.filename
MsgBox Val(idactual)
Exit Sub
If Conn1.State = 1 Then
Conn1.Close
End If
base = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=base.mdb"
AccessConnect = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=datos.mdb"
Conn1.ConnectionString = AccessConnect
Conn1.Open AccessConnect
Set Rs1 = New adodb.Recordset
Rs1.Open "SELECT * FROM trabajos", Conn1, adOpenDynamic, adLockOptimistic
''Do Until Rs1.EOF Or Rs1.BOF
Rs1.AddNew
Rs1("clienteid") = Val(idactual) ''= Rs1.Fields.Item("id").Value
Rs1("trabajo") = cd.filename
Rs1.AddNew
Conn1.Close
Call actualizar

Exit Sub
I get the MS ODBC Couldn Find File (Unknown) error...
Any ideas???
Its frustrating
Cya & Tnx!

Common Dialog. .and Listbox . Also A New Error
ok theres a text.txt that countains somehting like this
a word
2nd word
3rd word
etc
etc


so when I open to listbox loads like this
a word
2nd word
3rd word
....

Runtime Error In Common Dialog
Hello, I have this error, when I close a common dialog box in my app, it has a runtime error. Also happens when I click "cancel". This is because nothing is selected, anyone know how to fix this? Thanks.

Common Dialog Component Error
I know I should know how to fix this, but I don't so, I'm having trouble with my common dialog box. Everything works but when I click cancel when the dialog box is open, there is an error. How do I fix this error from showing up, and when you click cancel, the common dialog box (cd1) just dissapears?

Excel Common Dialog Error
In relation to my previous message... (common dialog license)

I think I should have specified that the program is written behind excel. At one point I was getting the same error in Excel running on the win98 platform, to solve this I copied the OCX file from the original win98 CD. This worked but When I open the spreadsheet on the NT platform I got the same error, as I am not hugely experienced in VB I hope this isn't a stupid question but would NT require a different OCX or DLL file

Again thanks for any help
Steve

Question: Common Dialog Box Error.
Greetings.


I wrote this file open Dialog in VB 4, and it did work, however it seems to have Broke, and i was wondering what went wrong??? maybe someone can help.


this code did not break until i upgraded to VB 5.0. now i get the Error Method or data member not found.


i dont want to have to rewrite my app in VB 5.0 from scratch, can someone help direct me in the correct path... thanks.



Sub FOpenProc()

Dim RetVal

On Error Resume Next

Dim OpenFileName As String

frmMDI.CMDialog1.Filename = ""

frmMDI.CMDialog1.ShowOpen

If Err 32755 Then ' User chose Cancel.

OpenFileName = frmMDI.CMDialog1.Filename

' If the file is larger than 65K, it can't

' be opened, so cancel the operation.

If FileLen(OpenFileName) > 65000 Then

MsgBox "The file is too large to open."

Exit Sub


it is this line : frmMDI.CMDialog1.Filename = "" in the code that is causing the problem,,,, according to VB. but it may be anywhere in VB. this is the file, open box. nothing spectaculer here. im just at a loss.

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