Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184

    Angry Unanswered: OLE Ojbects- annoying default features

    I'm working on a table with OLE objects. I've created code that opens the Insert OLE object dialog box when the user doubleclicks the field. If they cancel the operation, a messagebox pops up that says "No file added." HOWEVER, when they cancel, Access pops up an error message that says "OLE Object is empty.", and it goes on to tell the user to put a file in the OLE field. How do I keep this error message from popping up?

    A second annoying thing is that it opens the file after the user inserts it. Can I stop this?

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    At the beginning of your code routine try placing this line:

    On Error Resume Next

    Now...Just before your line to open the Insert dialog, try inserting the line below:

    DoCmd.Setwarnings False

    and near the end of your code, plase this line....

    DoCmd.Setwarnings True

    You want to make sure you set warnings to True again...no matter what!

    Let me know if this helps.


  3. #3
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184
    Here is the code I have so far. I got rid of my error message, put in the code you recommended, but it still gives the same error. I think the error message is happening after the subroutine closes because the box's default double-click action is to open the file, so it's trying to open the file and can't find one.

    --------------------------------------------------------------

    Private Sub OLEAttachment_DblClick(Cancel As Integer)

    DoCmd.SetWarnings False 'No error messages for this button
    On Error Resume Next

    'If there is no file here, then open Insert dialog box
    If OLEAttachment.OLEType = acOLENone Then
    ' Display Insert Object dialog box.
    OLEAttachment.Action = acOLEInsertObjDlg
    End If

    DoCmd.SetWarnings True 'Turn error messages back on

    End Sub

  4. #4
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184
    When I looked at it again, I saw the AutoActivate option was set to "double-click", so it was trying to open the file each time I double-clicked, even when I had code for double-clicking. So, I'm going to leave double-click for opening an existing file, and single-click for adding a new one. The code I have works fine when I copy it to the single-click event. This also solves the annoying automatic opening thing I mentioned.

  5. #5
    Join Date
    Sep 2007
    Posts
    148
    This thread has helped solved my problem. Thank you

    In case someone want to add the feature to open the link picture if there is one in the box, here is the code. I move to focus to another text box if the OLE object is empty in order to avoide the annoying error message

    Private Sub OLECompanyLogo_Click()

    Dim conUserCancelled As Integer

    ' Error message returned when user cancels.
    conUserCancelled = 2001
    On Error GoTo ButtonErr
    If OLECompanyLogo.OLEType = acOLENone Then
    ' No OLE object created.
    ' Display Insert Object dialog box.
    OLECompanyLogo.Action = acOLEInsertObjDlg

    Else

    OLECompanyLogo.Action = acOLELinked
    End If
    Exit Sub

    ButtonErr:
    If Err = conUserCancelled Then ' Display message.
    MsgBox "You clicked the Cancel button; " _
    & "no object was created."
    Me.txtNotes.SetFocus
    End If
    Resume Next
    End Sub
    Last edited by sweetmail; 11-06-08 at 17:39.

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Good post sweetmail.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •