PDA

View Full Version : Saving an image on the clipboard to the attachment type in Access 2010



NW27
08-25-2011, 11:05 PM
Hi All,
Two weeks ago I started to use Access for the first time and yesterday looked at VB. Mind you, I have extensive experience in Pascal, assembler, some C and QBasic/GWBasic in the DOS days.

I'm using Access 2010 and the attachment type in a table. I can generate a form and load an image from a file into this table.
What I would like to do is save the image captured onto the clipboard into the attachment field of the table.
Ie ALT+Printscreen then press a button on the Access form that puts this into the attachment field. Pressing Cntl+V on the attachment doesn't work :(

I imagine the VB code for the button press would probably be a two part process -
1. Get the image from the clipboard and save as a file ie JPG.
2. Load the JPG file into the attachment field.

I have the below code but it references a excel variable "xlBitmap" and won't compile in Access VB?

Any help for this newbie would be greatly appreciated.
Neil.

Private Sub Command21_Click()
Dim vFile As Variant, lPicType As Long, oPic As IPictureDisp
'Get the filename to save the bitmap to
'vFile = Application.GetSaveAsFilename(InitialFileName:="", filefilter:="Bmp Files (*.bmp), *.bmp")
vFile = "Chart.BMP"
If vFile <> False Then
'Get the type of bitmap
lPicType = xlBitmap
'Retrieve the picture from the clipboard...
Set oPic = PastePicture(lPicType)
'... and save it to the file
'a little check to see if there's something on the clipboard
If Not oPic Is Nothing Then
SavePicture oPic, vFile
Else
MsgBox "No picture on clipboard.", vbInformation, "Picture paste ..."
End If
Else
MsgBox "You haven't specified a filename.", vbInformation, "Picture paste ..."
End If
End Sub

HiTechCoach
08-27-2011, 08:37 AM
Welcome to the forum and to Access.

The Attxchwemtn data is a new thing in Access. It was first introduced in Access 2007 with the new ACE (.accdb) database format.

Inserting fiels or images not an Access database has always been a source of database bloat. With Access 2007 this has got better. But you are still limited to a 2 gig files size for a single database (.accdb). By using a separate back end for just the images you get a little more space.

I have have many issues with the new attachment data type. I don;t use it for any apps I create. I just store the path the the file. I have created an example. See: Document Links 2 (http://www.hitechcoach.com/index.php?option=com_docman&task=doc_details&gid=14&Itemid=28)

I would also urge you to split your database into a app/front end and data/back end. I do all apps this way.

See: Splitting your Access database into application and data (http://www.hitechcoach.com/index.php?option=com_content&view=article&id=35:split-your-access-database-into-application-anddata&catid=65:split-database)

Back to saving the image from the clipboard to a file.

I have not tried to do this before with automation/VBA code. If I were to try it I would first need to get the image from the clipboard to a control or application that had the ability to save the image. Since you have Excel VBA, you could use Excel Automation to take advantage of the Excel Object Model to do the saving. You may be able to use an Windows API to paste the image from the clipboard to a image control on a form. Then use VBA code to save the image from the control to a file. This might help: LoadSaveJPG (http://www.lebans.com/loadsavejpeg.htm)

NW27
08-29-2011, 11:47 PM
Hi Boyd,
Thanks for the response. There is some great info here.
I'll look at splitting my database into application and data.
Neil.

HiTechCoach
08-30-2011, 07:12 AM
You're welcome.

Let us know if we can assist you any further.