Select File Dialog for VBA

1836
2
04-01-2011 07:29 AM
MattFancher
New Contributor III
I included a "select file" button on a VBA form.  The intent of the button is to allow the user to choose a PDF file to save to a specified directory.  The URL of the PDF will then be stored in the attribute table of an associated feature class so the file can be accessed via a link in the identify window.  I got this to work on my desktop, but it bombs when I try to run the procedure on other computers in my office.  This is the sub that fires when the button is clicked:

Private Sub cmdSelectFile_Click()
    Dim CDLG As Object
    Set CDLG = CreateObject("MSComDlg.CommonDialog")
    With CDLG
      .DialogTitle = "Select a File"
      .Filter = _
        "PDF Documents|*.pdf"
      .ShowOpen
      m_strFileURI = .FileName
      m_strFileName = .FileTitle
      txtDocLink.Text = .FileTitle
    End With
    Set CDLG = Nothing
End Sub

It crashes on this line:

Set CDLG = CreateObject("MSComDlg.CommonDialog")

I'm guessing it runs on my desktop because I have Visual Studio installed, giving me license to use the library associated with the object.  Is that close?

I've also attempted to use the GxDialog class, but I don't really like that solution, because there is not an ObjectFilter for PDFs.  At least not one that I've found.

Can anyone suggest a solution, or a better way for me to do this?  Thank you very much in advance!  BTW, I'm running ArcGIS 9.3.1 SP1 on Windows XP SP2, and if I wasn't clear this is all in VBA just stored within the map document.
0 Kudos
2 Replies
NeilClemmons
Regular Contributor III
There's no need to use CreateObject.  The Microsoft Common Dialog control is an actual Form control that you can add to the toolbox and drop onto your dialog in the designer.  You then access it in code just like you would any other control on the dialog.  The control is included in a system file (comdlg32.ocx) that should be on any machine running Windows.
0 Kudos
MattFancher
New Contributor III
Neil,
That fixed it.  I used the control as you suggested.  Thank you.
Matt
0 Kudos