mfancher

Select File Dialog for VBA

Discussion created by mfancher on Apr 1, 2011
Latest reply on Apr 1, 2011 by mfancher
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.

Outcomes