Results 1 to 9 of 9

Thread: CommonDialog.InitDir not functioning in VB6

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    2

    CommonDialog.InitDir not functioning in VB6

    I have an app that allows the user to select a picture to be included with the record when the record is being added or edited. Setting the .initdir to app.path & "\Pictures" does not work. It always finds the same directory which also contains pictures but for the wrong application. I have tried using the Environ() function with no help.

    I am using Visual Basic 6.0 on WIndows 7.

    Thanks for any help you can provide.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: CommonDialog.InitDir not functioning in VB6

    Go to OPENFILENAME structure, scroll down to lpstrInitialDir to see the rules.

    I can't believe how many times we have to answer this same question here. Doesn't anybody even try a search first?

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    2

    Re: CommonDialog.InitDir not functioning in VB6

    If you have solved it before, I wasn't able to find anything that works. I tried the reset to .filename and that doesn't work for me.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: CommonDialog.InitDir not functioning in VB6

    It is working as intended.

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: CommonDialog.InitDir not functioning in VB6

    Hello cwmusicman,

    since Windows 7 and later, the common dialog remembers the last location selected by the user even if you supply a default path.

    For better or worse (I think it is worse), it works like that now.
    And there is no easy workaround.
    There are some workarounds that I remember I've read on internet, but I don't have the addresses of those pages.

  6. #6
    gibra
    Guest

    Re: CommonDialog.InitDir not functioning in VB6

    Quote Originally Posted by cwmusicman View Post
    If you have solved it before, I wasn't able to find anything that works. I tried the reset to .filename and that doesn't work for me.
    Publish a VBP project (zipped) that reproduce the problem.

  7. #7
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: CommonDialog.InitDir not functioning in VB6

    Quote Originally Posted by gibra View Post
    Publish a VBP project (zipped) that reproduce the problem.
    That can't be possible, because the behaviour depends of previous actions in the end user machine.

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: CommonDialog.InitDir not functioning in VB6

    What worked for me was always also specify a filename, even if there is not filename yet. It's ugly, but worked.
    An alternative is using the IFileDialog:
    http://www.vbforums.com/showthread.p...ista-(No-TLBs)

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,652

    Re: CommonDialog.InitDir not functioning in VB6

    Since the above doesn't go into details, there's several ways of handling this with IFileDialog.

    First, you can have the last folder remembered on a per-dialog basis, so that no other time the dialog is opened does it effect the last folder your user selected. See [VB6, Vista+] Remember Open/Save state per-dialog instead of per-app (IFileDialog)

    The second, you can always clear the last saved folder, that way the default folder is always shown since there's no old one, by calling the .ClearClientData method before setting the default folder.

    And third, you can manually navigate to your desired folder by calling the .SetFolder method.

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