Clear cmnDialog path

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Clear cmnDialog path

Post by D Willett »

Hi

Just a little trouble with this code snippet.
When the dialog opens it remembers it's last path. I tried to clear prior and post with:
CmnDialog1.FileName = ""
But the path is still remebered.
Can someone see my problem in the code?:

Code: Select all

Private Sub proPubDocs_Click(Index As Integer)
' CancelError is True.
   CmnDialog1.CancelError = True
   On Error GoTo ErrHandler
   ' Set filters.
   CmnDialog1.FileName = ""
   CmnDialog1.Filter = "PDF Files (*.pdf)|*.pdf"
   ' Specify default filter.
   CmnDialog1.FilterIndex = 2
   ' Display the Open dialog box.
   CmnDialog1.ShowOpen
   CmnDialog1.InitDir = "L:\MMpdf\MMDocs\Public Docs\"
   Me.AcrobatPath = CmnDialog1.FileName
   Me.PDF1.LoadFile Me.AcrobatPath
   CmnDialog1.FileName = ""
   Exit Sub

ErrHandler:
   ' User pressed Cancel button.
   Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath
End Sub
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Clear cmnDialog path

Post by HansV »

Does

CmnDialog1.InitDir = ""

work better?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Clear cmnDialog path

Post by D Willett »

Hi Hans
Not sure ( at home ) but I'll try it in the morning.
But just for info, kicking myself already because it seems so obvious !!! :groan:

Regards
Cheers ...

Dave.

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Clear cmnDialog path

Post by D Willett »

Hi Hans

I changed the lines and moved the command before the correct directory is called, still loads showing the last known location ??

Code: Select all

Private Sub proPrivDocs_Click(Index As Integer)

' CancelError is True.
   CmnDialog1.CancelError = True
   On Error GoTo ErrHandler
   ' Set filters.
   
   CmnDialog1.Filter = "PDF Files (*.pdf)|*.pdf"
   ' Specify default filter.
   CmnDialog1.FilterIndex = 2
   ' Display the Open dialog box.
   CmnDialog1.ShowOpen
   CmnDialog1.InitDir = ""
   CmnDialog1.InitDir = "C:\MM-Utilities\MyDocs\"
   Me.AcrobatPath = CmnDialog1.FileName
   Me.PDF1.LoadFile Me.AcrobatPath
   CmnDialog1.InitDir = ""
   Exit Sub

ErrHandler:
   ' User pressed Cancel button.
   Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath
      

End Sub
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Clear cmnDialog path

Post by HansV »

You have two lines:

Code: Select all

   CmnDialog1.InitDir = ""
   CmnDialog1.InitDir = "C:\MM-Utilities\MyDocs\"
The first clears the folder to be used but the second sets it to C:\MM-Utilities\MyDocs again. Does the dialog open there or to another folder?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Clear cmnDialog path

Post by D Willett »

Hi Hans

I didn't explain properly.
There are two instances of the dialog. One to open private docs on the local machine and one to open public docs on the network:
CmnDialog1.InitDir = "C:\MM-Utilities\MyDocs\"
CmnDialog1.InitDir = "L:\MMpdf\MMDocs\Public Docs\"

The dialog always opens on the local path ??

Code: Select all

Private Sub proPrivDocs_Click(Index As Integer)

' CancelError is True.
   CmnDialog1.CancelError = True
   On Error GoTo ErrHandler
   ' Set filters.
   
   CmnDialog1.Filter = "PDF Files (*.pdf)|*.pdf"
   ' Specify default filter.
   CmnDialog1.FilterIndex = 2
   ' Display the Open dialog box.
   CmnDialog1.ShowOpen
   CmnDialog1.InitDir = ""
   CmnDialog1.InitDir = "C:\MM-Utilities\MyDocs\"
   Me.AcrobatPath = CmnDialog1.FileName
   Me.PDF1.LoadFile Me.AcrobatPath
   CmnDialog1.InitDir = ""
   Exit Sub

ErrHandler:
   ' User pressed Cancel button.
   Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath
      

End Sub

Private Sub proPubDocs_Click(Index As Integer)
' CancelError is True.
   CmnDialog1.CancelError = True
   On Error GoTo ErrHandler
   ' Set filters.
   
   CmnDialog1.Filter = "PDF Files (*.pdf)|*.pdf"
   ' Specify default filter.
   CmnDialog1.FilterIndex = 2
   ' Display the Open dialog box.
   CmnDialog1.ShowOpen
   CmnDialog1.InitDir = ""
   CmnDialog1.InitDir = "L:\MMpdf\MMDocs\Public Docs\"
   Me.AcrobatPath = CmnDialog1.FileName
   Me.PDF1.LoadFile Me.AcrobatPath
   CmnDialog1.InitDir = ""
   Exit Sub

ErrHandler:
   ' User pressed Cancel button.
   Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
   Me.PDF1.LoadFile Me.AcrobatPath
End Sub
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Clear cmnDialog path

Post by HansV »

I'm afraid I can't explain that, and I cannot test it since I can't use the common dialog any more. Sorry!
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Clear cmnDialog path

Post by D Willett »

Don't worry Hans.

When I find the solution I'll post it on the site for others to benefit from.
Thank you for your time anyway and have a great weekend. :grin:
Cheers ...

Dave.

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Clear cmnDialog path

Post by D Willett »

This seems to work:
( But I would appreciate comments )

Code: Select all

Private Sub proPrivDocs_Click(Index As Integer)

    On Error GoTo cancel_error
    
    With CmnDialog1
        '~~> Set the Title of the Dialog Box
        .DialogTitle = "Open"
        '~~> Set the Initial directory
        .InitDir = "C:\MM-Utilities\MyDocs\"
        '~~> Set the Filter for the files that you want to open
        .Filter = "pdf Files (*.pdf)"
        '~~> Displays the Open Dialog Box
        .ShowOpen
    End With
    
   Me.AcrobatPath = CmnDialog1.FileName
   Me.PDF1.LoadFile Me.AcrobatPath
Exit Sub

cancel_error:
     If Err.Number <> vbCancel Then
          MsgBox Err.Description
     End If
      

End Sub

Private Sub proPubDocs_Click(Index As Integer)
    On Error GoTo cancel_error
    
    With CmnDialog1
        '~~> Set the Title of the Dialog Box
        .DialogTitle = "Open"
        '~~> Set the Initial directory
        .InitDir = "L:\MMpdf\MMDocs\Public Docs\"
        '~~> Set the Filter for the files that you want to open
        .Filter = "pdf Files (*.pdf)|*.pdf"
        '~~> Displays the Open Dialog Box
        .ShowOpen
    End With
    
   Me.AcrobatPath = CmnDialog1.FileName
   Me.PDF1.LoadFile Me.AcrobatPath
Exit Sub

cancel_error:
     If Err.Number <> vbCancel Then
          MsgBox Err.Description
     End If

End Sub
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Clear cmnDialog path

Post by HansV »

Ah yes, it makes sense to set the initial folder before displaying the dialog. Thanks!
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Clear cmnDialog path

Post by D Willett »

:innocent: Glad to be of service Hans !! :grin:
Cheers ...

Dave.