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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

764 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