Results 1 to 8 of 8

Thread: [Solved] Common Dialog Control Problem with .InitDir

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    28

    [Solved] Common Dialog Control Problem with .InitDir

    I can't seem to get .Initdir to set the directory more then once, when I first call the Common Dialog Control to .Initdir to app.path it does it, however if I do it again it goes to the directory it was last in opposed to app.path.

    I can post the code if it's needed.
    Last edited by TheT; Apr 8th, 2007 at 10:44 AM.

  2. #2
    Addicted Member
    Join Date
    Jul 2006
    Location
    Adelaide, Australia
    Posts
    204

    Re: Common Dialog Control Problem with .InitDir

    post the code, but that sounds kinda strange... it usually accepts the changes, i think...

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Common Dialog Control Problem with .InitDir

    Quote Originally Posted by TheT
    I can post the code if it's needed.
    Please do...I can't replicate this problem.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    28

    Re: Common Dialog Control Problem with .InitDir

    Code:
    Private Sub btn_addobj_Click()
    On Error GoTo ErrorHandler
        With cdc_add
            .InitDir = App.Path
            .CancelError = True
            .DialogTitle = "Open File"
            .Filter = "All Files (*.*)|*.*"
            .ShowOpen 'Show the open file dialog.
            obj(Numofobj) = .FileName
            MsgBox obj(Numofobj) 'Display Info
            lis_obj.AddItem (.FileName)
            Numofobj = Numofobj + 1 ' Increase by 1
            .InitDir = App.Path
        End With
        
        Exit Sub
    ErrorHandler:
        If Err.Number = 32755 Then
            'User pressed cancel.
            MsgBox "User pressed cancel", vbInformation
        Else
            'Some other error.
            MsgBox Err.Description, vbExclamation, "Error (#" & Err.Number & ")"
        End If
    End Sub

  5. #5
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: Common Dialog Control Problem with .InitDir

    I guess it's a bug. See this.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Common Dialog Control Problem with .InitDir

    Either that or its only meant to "initially" set the path when its first called in tha instance of the running of the program.

    I did this and it works only the very first time. Hence - "Initial directory".

    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     'Forces the dialog box to set the current directory to what it was when the dialog box was opened.
    5.     CommonDialog1.Flags = cdlOFNNoChangeDir
    6.     CommonDialog1.InitDir = "C:\"
    7.     CommonDialog1.ShowOpen
    8. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    28

    Re: Common Dialog Control Problem with .InitDir

    Quote Originally Posted by minor28
    I guess it's a bug. See this.
    That did the trick, thanks Minor28!

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: [Solved] Common Dialog Control Problem with .InitDir

    Thanks for letting us know you have your answer. The next time you may find it easier to do that by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width