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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export Pictures from Access DataBase into Image File (*.jpg, *.bmp)

Status
Not open for further replies.

Aivars

Programmer
May 4, 2001
687
LV
Hi!
Our data system have very big database with photos (up to 700Mb). Accordingly it's not possibly to export/import data. Also cannot compact this monster. How to do exporting of photos from Access database into some image format files like JPEG, Bitmap etc.

Thanks!
Aivars
 
Hallo, again!

Don't nobody help my, yah?
Aivars
 
Apparently Access changes binary files around when it saves them as OLE objects. Consequently, the only way to get pictures back out of an Access database is to simulate the user actions of cutting and pasting. I curse Microsoft for forcing me to use the sendkeys statement.

This is a really big hack. I don't have time to clean it up. It worked for me.

Option Compare Database
Option Explicit

Private Sub Command0_Click()
On Error GoTo err_Handler
Dim nCounter As Long
Dim nIndex As Long

'You should have a form, named "Form1".
'This form should be bound to the recordset containing the pictures you
' want to export. If not every record has a picture, you should bind
' the form to a query that selects where the OLE field Is Not Null.
'On this form you should have a bound OLE control named "OLE1". This
' control should be bound to the OLE field containing the pictures
' you want to export.
'On this form you should also have a command button named
' Command0 (the click event of this command button runs the code you
' are currently reading)


DoCmd.SelectObject acForm, "Form1"

Do While True 'Have I mentioned this is a big hack?

nCounter = nCounter + 1

DoCmd.GoToControl "OLE1"

DoCmd.RunCommand acCmdCopy

Shell "c:\winnt\system32\mspaint.exe", vbNormalFocus 'Your path to paint may vary.
For nIndex = 1 To 100
DoEvents
Next

SendKeys "^v", True 'Paste the image into paint
SendKeys "{ENTER}", True 'Paint may ask if you want to enlarge the image.
For nIndex = 1 To 100
DoEvents
Next

SendKeys "%f", True 'Access the file menu
For nIndex = 1 To 100
DoEvents
Next

SendKeys "s", True 'Select Save
For nIndex = 1 To 100
DoEvents
Next

SendKeys "pic" & "mechanismforsequentialnaming" & ".jpg" 'Name the file you are saving
For nIndex = 1 To 100
DoEvents
Next

SendKeys "{TAB}j{TAB}", True 'Specify jpeg format
For nIndex = 1 To 100
DoEvents
Next

SendKeys "{ENTER}", True 'Save the file
For nIndex = 1 To 100
DoEvents
Next

SendKeys "%f", True 'Access the file menu
For nIndex = 1 To 100
DoEvents
Next

SendKeys "x", True 'Select Exit (closing paint)
For nIndex = 1 To 100
DoEvents
Next

DoCmd.SelectObject acForm, "Form1" 'Set the focus back to the form

DoCmd.GoToRecord acDataForm, "Form1", acNext 'Move to the next record

Loop

Close #1

Exit Sub


err_Handler:
MsgBox Err.Description
Close #1
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top