2

Just for some background, I'm a mechanical engineer at a company and the older folks here created a database in Access 2003 which basically takes an AutoCAD Drawing or a Picture OLE and plops it in a nicely framed report with a bunch of other information. I've been making some modifications to that database, one of which is to store all OLEObjects as links to actual files in our shared network. Every new file that has been added to the database for the past week or so has been linked and the guys seem to have gotten the hang of it.

My problem at this point in time is to try and retrieve all the Objects that are embedded in the tables. I've tried Lebans OLE to Disk but that doesn't seem to work with AutoCAD Drawings (which are .dwg and .dxf files) nor does it work with "Picture".

I know this is a quite controversial topic seeing as how I'm not providing any code to start with, but I think this is too complicated for me to even begin doing and I'm in over my head. Extracting the OLEObjects by hand isn't feasible since there's over 8000 of these spread through several databases. Is there any way to automate the extraction via code?

Thanks in advance,

Rafael.

Erik A
  • 31,639
  • 12
  • 42
  • 67
Rafael
  • 81
  • 1
  • 11
  • 2
    I don't have experience with AutoCAD drawing OLE objects, but can you check which verbs it supports? Most objects support a verb to save it to disk. I have an answer on how to automate OLE object operations [here](https://stackoverflow.com/a/48711364/7296893), specifically creating new OLE objects, but that should give you a starting point. To determine which verbs an OLE object supports, you can use the acOLEFetchVerbs property (see [this docs page](https://learn.microsoft.com/en-us/office/vba/api/access.boundobjectframe.action) for a little more detail. – Erik A Jun 21 '19 at 14:26
  • 2
    Also, you may not have shared any code, but you've put in research effort, which is appreciated, and it's a narrowly defined (but difficult) subject. I hope someone with experience in AutoCAD drawing objects might be able to help, added a tag to see if some of the experts on it can provide insight – Erik A Jun 21 '19 at 14:30
  • Thanks for the reply Erik. I tried getting the verbs through a cmdbutton on a form with a boundOLE and it returns as two blank strings, not sure if that's me doing something wrong or if it's specific to AutoCAD... I also took a look at the link you sent and even though that provides a basis on how to interact with the objects I can't for the life of me figure out how to retrieve the info let alone save it outside of Access... – Rafael Jun 21 '19 at 15:08
  • See more reference code on iterating verbs [here](https://learn.microsoft.com/en-us/office/vba/api/access.boundobjectframe.objectverbs). The verbs are dependent on the type of ole object. Haven't got AutoCAD, but they're usually not empty strings. – Erik A Jun 21 '19 at 15:26
  • The snippet at the end of that page is exactly what I was using, and it definitely returns empty... – Rafael Jun 21 '19 at 15:32
  • I'm afraid I can't do a lot, since I haven't got AutoCAD. I know I've written an extractor once by invoking the copy action, then accessing the clipboard and writing the contents to disk, but what's put on the clipboard is also dependent on the type of object. I haven't got that code on me atm, but if it helps, I can share code to iterate clipboard formats and extract the corresponding content in VBA tomorrow. But I don't know if the clipboard content is easily converted to a file. – Erik A Jun 21 '19 at 15:40
  • I'm not sure if this is what you mean by copy+pasting, but I can tell you for a fact that if I copy the OLEObject from the table, I can't paste it in a Windows Folder. I can paste it in an Excel file or another Access table/record with an OLEObject field, but that's it... I really appreciate the effort Erik, hopefully someone can shine a light on this! – Rafael Jun 21 '19 at 15:46

1 Answers1

1

If you access the Object property of the Bound Object Frame control, for an AutoCAD Drawing this should return the AutoCAD Document Object. You can then invoke the SaveAs method of the Document object to save the file to a known location.

For example, something like:

With Me.MyBoundObjectFrame.Object
    .SaveAs "Drive:\YourPath\YourDrawing.dwg"
End With

Where MyBoundObjectFrame is the name of your Bound Object Frame control.

This works successfully in my limited testing.

Lee Mac
  • 15,615
  • 6
  • 32
  • 80
  • Wow, that's so simple, great idea! I'll give it a try as soon as possible and post back results! – Rafael Jun 22 '19 at 19:19
  • It worked wonderfully for the AutoCAD files, thanks a lot! Let me just hijack this and ask if you know how to retrieve the "Picture" OLE? – Rafael Jun 24 '19 at 10:01
  • 1
    I'm glad it works for you. Unfortunately, my knowledge of this area does not extend to images, and so you may need to raise that as a separate question tagged accordingly for the experts in that area. – Lee Mac Jun 24 '19 at 12:14