Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Aug 2002
    Location
    Michigan, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inserting OLE Object (2000)

    I have an OLE field in my table and the same OLE field on my form. Does anyone know how I can create a command button that allows you to insert a file into this field? The file would then sit in the form as an "attachment" icon, and you could double-click this to launch the attachment. On the form, it would be the same as selecting the following commands: "Insert Object...Create from File." Any help is greatly appreciated.

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Inserting OLE Object (2000)

    I believe if you use the code command:
    <font color=blue>DoCmd.RunCommand acCmdInsertObject</font color=blue>
    that will have the same effect as the menu command, though I think you will still have to specify the Create From File option. Hope this gets you further down the road.
    Wendell

  3. #3
    Star Lounger
    Join Date
    Aug 2002
    Location
    Michigan, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inserting OLE Object (2000)

    Thanks for your response WendellB. I have used that, but the problem is I can't use SendKeys to send information to this dialog box for some strange reason (to further automate it - select "Create from File, etc.). Well, if you have any other insight, I would appreciate it - thanks again.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Inserting OLE Object (2000)

    OLE controls have several properties for manipulating them, such as SourceDoc and Action. You can use these, together with the Open dialog you got in another thread, to insert a file.

    Let's say you have an OLE control objOLE, and a command button cmdOpen. The OnClick routine for the button could be something like:

    Private Sub cmdOpen_Click()
    Dim dlg As New CommonDialogAPI
    Dim lngFormName As Long
    Dim lngAppInstance As Long
    Dim strInitDir As String
    Dim strFileFilter As String
    Dim lngResult As Long

    lngFormName = Me.hWnd
    lngAppInstance = Application.hWndAccessApp
    strInitDir = "C:"
    strFileFilter = "All files (*.*)" & _
    Chr(0) & "*.*" & Chr(0)

    lngResult = dlg.OpenFileDialog(lngFormName, _
    lngAppInstance, strInitDir, strFileFilter)

    If dlg.GetStatus = True Then
    With objOLE
    .SourceDoc = dlg.GetName
    .Action = acOLECreateEmbed
    End With
    End If

    Set dlg = Nothing
    End Sub

    This code uses the CommonDialogAPI class module from <post#=170545>post 170545</post#>.

  5. #5
    Star Lounger
    Join Date
    Aug 2002
    Location
    Michigan, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inserting OLE Object (2000)

    HansV - THANK YOU, THANK YOU, THANK YOU!!! You were totally reading my mind with where I wanted to go with this (oh my god - you even picked up on my other thread question)! I just have one more question for you, guru. I cannot figure this one out either - is it possible to have the path of the file you select appear within the OLE object (mine is called objMapsDirs). I can get the proper icon to display, but it always just says "Text Document." Ideally, I would like to have it show the text file icon, and beneath it then display the file name OR the file name/path. Is this possible??? Thanks again, I am really grateful for your help on this one!!!

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Inserting OLE Object (2000)

    Hi Steve,

    I don't know of a way to display the file name inside the OLE control. You could, however, place a label on your form and set the caption of the label to dlg.GetName.

    Regards,
    Hans

  7. #7
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Inserting OLE Object (2000)

    Now that we've led you down the garden path and you're all set to use OLE objects, you should be aware of the downside. Access databases bloat like crazy when you use OLE embeded or linked objects. That is especially true of graphic objects - it isn't uncommon for a database to grow by 1MB for every object embeded. I've never gotten a completely satisfactory answer as to why that is, but I suspect they are basically storing a conversion/display routine for every object, whether they are the same time or not. Others may want to chime in here, but if you plan to store lots of objects (say 100 or more), life may get complicated.
    Wendell

  8. #8
    Star Lounger
    Join Date
    Aug 2002
    Location
    Michigan, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inserting OLE Object (2000)

    WendellB, this is a very good point. I am limiting the user so they can only insert text files as "attachments." FYI, I also discovered that it is a known Microsoft bug (with no fix I might add) if you attempt to package a 0kb file (you will get a "not enough memory" error). I have my code running strong now, and it's looking great. Thanks again for all your help!

  9. #9
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Inserting OLE Object (2000)

    That raises an interesting question. I'm not sure what size impact a text file would have since it is just character mode data. It doesn't seem you should need a text converter to display plain text. More to the point, why not simply store the data in a memo field and avoid the hassle of OLE objects?
    Wendell

Posting Permissions

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