Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write Ole Package picture from OLE Object Access field into some sort of control in Excel sheet

Status
Not open for further replies.

lameid

Programmer
Jan 31, 2001
4,208
US
After poking the bear and touring the internet I finally understand why people always said storing pictures in Access is bad, it is because they are invariably put in by bound controls or directly into the tables via native Access UI which means an entire Ole Package wrapper around the file making them difficult to do anything constructive with as opposed to an actual binary stream that can be easily read out to a file and be used in a rational manner.

However embedded Ole wrapper packages is what I have and I am hoping there is some easy way to consume the entire package in Excel.

Can I take an embedded Ole object that is a picture and write it into some sort of control in Excel and have it display the picture - preferably from a recordset?

I am using Office 2013.

A less favorable prospect would be to open the picture for each record, save it and then use files directly - I can find using files but did not pay much attention as best I can tell no way to save files. I am assuming the saving would have to be manual but if there is code / automation I would welcome it. Currently I have Win 7 and paint... obviously OS upgrade is coming in the not too distance future thanks to the end of update support for Win 7 - betting I have 3 to 6 months left on it.

The closest thing to useful I found is the below but that is going the wrong way. I have not played with bound ole objects. I guess that is next on my search for the kitchen sink.

 
Out of that stackoverflow post, I finally figured out how to functionally double click the bound object frame for a picture which opens paint on my machine...

Where bofLogo is the bound object frame control containing the image.

Code:
  bofLogo.Verb = acOLEVerbOpen
  bofLogo.Action = acOLEActivate

I did not get the sendkeys quite right to save it but I did find that doing save as manually did not yield a file I could reopen in paint. It appears corrupt not unlike streaming out the entire blob to disk. My question then is what am I doing wrong that opening the Ole object in application and doing save as does not yield good results?
 
Figured out what I was doing wrong... F12 does not work... you have to use other method but I have a new problem
*Note currently on Win 7 with paint...

Alt+f, Down, right, b...

Code:
  'Open Save As dialog with bitmap selected
  SendKeys ("%f") 'Alt+f
  SendKeys ("{DOWN}{RIGHT}") 'Down arrow, Right arrow: (Select Save Copy when opened from OLE object as this is on win 7)
  SendKeys ("b") 'b for bitmap option
  'Cursor lands in filename box

Catch 22 when I try to sendkeys the path into the file name at best I am loosing several leading characters.

I have even tried doevents and the sleep api call to no avail.

Even with the sleep, it seems to not put the cursor in the file name box while code is executing...

Dumbfounded at the moment.
 
Finally...


Code:
  'Open OLE Paint Picture
  bofLogo.Verb = acOLEVerbOpen
  bofLogo.Action = acOLEActivate 
  
  'Open Save As dialog with bitmap selected
  AppActivate "Paint" 'Activate paint application for good measure
  SendKeys ("%f") 'Alt+f
  SendKeys ("{DOWN}{RIGHT}") 'Down arrow, Right arrow: (Select Save Copy when opened from OLE object as this is on win 7)
  SendKeys ("b") 'b for bitmap option
  AppActivate "Paint" 'For some reason giving focus while the save as dialog box is loading is where the magic is
  
  Debug.Print strLogosPath & Me!txtLogoDescription & ".bmp"
  
  Sleep 750  'pause for save as dialog to load...

  
  SendKeys (strLogosPath & Me!txtLogoDescription & ".bmp") 'Enter File Name and path
  DoEvents
  SendKeys ("%s") 'alt + s (Save)
  DoEvents 'cede execution to OS
  Sleep 10 'Wait 10 ms because weird happens here in general with file I/O
  SendKeys ("%{F4}") 'alt + F4 - Close Windows Applicaiton (Paint)

It works but on a hope and a prayer, enjoy..
Solved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top