Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Common Dialogs

Posted on 2003-03-20
Medium Priority
Last Modified: 2010-05-01
I'm using this to open a file

CommonDialog.Flags = cdlOFNFileMustExist & cdlOFNHideReadOnly

my problem:
If I type something wierd that does not exist, it asks me If I want to create the file. If I say yes, my app will freeze.

what I need is, the user can't select yes! If file does not exist, he ain't going to open none, neither create!
Can someone help?

Thank you everyone!
Question by:igfp

Accepted Solution

Shaka913 earned 80 total points
ID: 8177212
Try this...
    CommonDialog1.Flags = cdlOFNHideReadOnly
    If Dir(CommonDialog1.FileName) = "" Then
        MsgBox "File Not Selected"
    MsgBox "File Selected : " & CommonDialog1.FileName
    End If

This will check to see if the file selected is real...

Good Luck
LVL 11

Expert Comment

ID: 8177587
With CommonDialog
    .CancelError = true ' exit if cancel is pressed
    .Flags = cdlOFNFileMustExist & cdlOFNHideReadOnly & cdlOFNPathMustExist
     on error resume next
    if (Err.Number = cdlCancel) then Exit sub ' cancel pressed
    if (.FileName = "") then Exit Sub ' no filename is selected
    if (Dir(.FileName) = "") then
        msgbox "File """ & .FileName & " Not Found!!!"
        Exit sub
    end if
End With

Good Luck!

Author Comment

ID: 8183675
this worked, it no longer asked whether i want to create the file it just says: "No mister" :p
And I made a cicle so it goes back to showdialog untill you choose something right! Thank you!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question