Link to home
Start Free TrialLog in
Avatar of K Dinsmore
K DinsmoreFlag for United States of America

asked on

How to resolve the following error when trying to use a browse button "Active X component can't create object"

Hi Experts. [Olaf are you out there?!]

I'm trying to use this code (below) via a button to allow my users to attach/embed a proof (.pdf file) in the job log (yes... still working on this job log - :p)

The code (which thank goodness I found posted here because it's exactly what I needed)
-------------------
Private Sub btnBrowse_Click()

    On Error GoTo err_btnBrowse_Click
   
    Const cdlOFNFileMustExist = 4096
    Const cdlOFNHideReadOnly = 4
    Const cdlCancel = 32755
   
    Dim dlgBrowse As Object
   
    Dim fullName As String, fileName As String
   
    Set dlgBrowse = CreateObject("MSComDlg.CommonDialog")
   
    dlgBrowse.CancelError = True

    'Change the line below to filter those file types you want to allow.  The part before the pipe symbol ("|") is just a text description of the filter.  The part after actually defines the filter.

    dlgBrowse.Filter = "Images (*.gif;*.bmp)|*.gif;*.bmp"

    dlgBrowse.FilterIndex = 1
    dlgBrowse.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
    dlgBrowse.DialogTitle = "Browse for Image"
    dlgBrowse.MaxFileSize = 2048
   
    dlgBrowse.ShowOpen
   
    fullName = dlgBrowse.fileName
   
    'Replace BoundOLE reference to the name of your Bound Object Control
    BoundOLE.SourceDoc = fullName
    BoundOLE.Action = acOLECreateEmbed
   
exit_btnBrowse_Click:

    Set dlgBrowse = Nothing
    Exit Sub
   
err_btnBrowse_Click:

    If Err.Number <> cdlCancel Then  'replace following with your own error handling code
        MsgBox Err.Description, vbExclamation, "Error: " & Err.Number
    End If
       
    Resume exit_btnBrowse_Click
   
End Sub
--------------------------
I've replaced the following lines (as noted by the author)

    'Replace BoundOLE reference to the name of your Bound Object Control
    BoundOLE.SourceDoc = fullName
    BoundOLE.Action = acOLECreateEmbed

to:

    'Replace BoundOLE reference to the name of your Bound Object Control (mine was JobProof)
    JobProof.SourceDoc = fullName
    JobProof.Action = acOLECreateEmbed
--------
note: JobProof is the field I want to store the OLE object (ultimately a .pdf)
------------------------------------

I've also changed the following lines:

    'Change the line below to filter those file types you want to allow.  The part before the pipe symbol ("|") is just a text description of the filter.  The part after actually defines the filter.

    dlgBrowse.Filter = "Images (*.gif;*.bmp)|*.gif;*.bmp"

to:

    dlgBrowse.Filter = "Images (*.gif;*.bmp)|*.pdf"

-------------
Problem 1:
Not sure if I've referenced everything correctly?!

Problem 2: (seems like the bigger issue)
I continue to get the error message "Active X component can't create object" when I go to click the button. I've done some research, both here on EE as well as Microsofts site - both suggest the following:

· Try registering the active x control via:
Start > Run > regsvr32 "C:\Program Files\Common Files\Microsoft Shared\DAO\DAO360.dll"

I did this, and it appeared to be successful, but I continue to get the error.

I've also tried to check my references (?) and nothing shows up missing (although I don't really have the skillset at this stage to know for certain)

I have no idea how to resolve this but I really need this functionality in the database. The button will ultimately read "Attach Proof" and prompt the user to browse their local hard drive for the actual proof which will be then be stored in the JobProof field of the the JobTicket.

Help is very-much appreciated!

Cheers! Katie (a.k.a. DesignCityStudio)



When trying to run the source code

ASKER CERTIFIED SOLUTION
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of K Dinsmore

ASKER

Arthur,
Keep in mind I'm pretty new to this DB stuff. I have no idea what line is causing the error but my 'guess', considering the error itself, would be:

 Set dlgBrowse = CreateObject("MSComDlg.CommonDialog")

But again, I have no idea.
That was definitely where the error is but I don't know how to fix this.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Olaf,
To answer your question "I don't know anything about your bound OLE-control, so this might still generate an error, but the other stuff should be running without any problem." --

The OLE-Control is named "JobProof" and the control resides in the subform JobTicket (SubFrm__JobTicketSubform)

Therefore, I've changed this:
       'Replace BoundOLE reference to the name of your Bound Object Control
       BoundOLE.SourceDoc = fullName
       BoundOLE.Action = acOLECreateEmbed

to this:
       'Replace BoundOLE reference to the name of your Bound Object Control
       JobProof.SourceDoc = fullName
       JobProof.Action = acOLECreateEmbed

And after doing everything from your last post, I am now recieving this error:

! Compile Error
Named argument already specified

And the debugger highlights this line of code:

OpenFile:=True, _

So, it's a new error and a new issue ;) Joy.

Cheers - Katie
Okay!
Well, I removed the second intstance of OpenFile=True,_ (it was in there twice) and [bing bang], I was able to get the open dialog box [beautiful thing] and now, I must have screwed the following refererences up:

       'Replace BoundOLE reference to the name of your Bound Object Control
       JobProof.SourceDoc = fullName
       JobProof.Action = acOLECreateEmbed

Because I am getting this error now:
run time error 2777
The class argument in the CreateObject function of the Visual Basic procedure you're trying to run is invalid.

Hmmm...
Oops... This was the line the debugger highlighted:
       JobProof.Action = acOLECreateEmbed
Katie,

sorry, I was a little too quick - when copying the stuff and adding my own I didn't see that there already was the OpenFile-statement, hence it was in there twice. Also, I failed to change your fullName-variable to varFilename (which is what I was using).
Since you are trying to use a PDF-file in an OLE-control - I don't know as to that will work at all (I'm not into using OLE much in general). You might have to use the ActiveX that Adobe is offering, but that will include the necessity to install/register it as well. Again, I don't have experience in that field, I just know there is a control that you can use in your application to show PDFs. I'd suggest going to the Adobe-website if you opt to go that way (that is, if you can't get it to work using an OLE-control) and searching there. A quick lookup there (with "ActiveX reader") turned up various results with http://www.adobe.com/support/techdocs/318268.html looking interesting.

Here's what your sub should really look like:

--- 8< ---
Private Sub btnBrowse_Click()
 on error goto HandleErrors
   Dim strFilter As String
   Dim varFilename as Variant

   strFilter = ahtAddFilterItem("", "PDF Files (*.PDF)", "*.pdf")
   varFilename = ahtCommonFileOpenSave( _
                Filter:=strFilter, _
                DialogTitle:="Please select a PDF-file...", _
                OpenFile:=True, _
                Flags:=ahtOFN_FILEMUSTEXIST or ahtOFN_EXPLORER or ahtOFN_LONGNAMES)

   if nz(varFilename,"")<>"" then
       'Replace BoundOLE reference to the name of your Bound Object Control
       BoundOLE.SourceDoc = varFilename
       BoundOLE.Action = acOLECreateEmbed
   end if

ExitHere:
   Exit sub

HandleErrors:
     MsgBox "Error: " & Error$ & "(" & Err & ")"
     Resume ExitHere
End Sub
--- 8< ---

Cheers,
Olaf
Well that seemed to do the trick! You're my hero (again) ;) Thanks  for your expertise!

Cheers - Katie
My pleasure! :-)

Cheers,
Olaf