Link to home
Start Free TrialLog in
Avatar of Moshe Singer
Moshe SingerFlag for United States of America

asked on

Insert an image .jpg format into a field on a form in Access 2016

In Access 97, when wanting to Insert an image .jpg format into a field on a form, I would click on the menu bar "Insert" then "Object" and then "Browse" and would be able to bring in any saved image.
Also, in my own custom menu I can use "Insert Object", to bring in the image to the selected field.

And now in Access 2016 with linked tables to SQL Server, I cannot find any code to bring in a graphics file to the selected field.
Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

With recent versions of Access, the new Attachment data type field is better for storing images (and other objects).  See my Access Archon article on using the Attachment field.Access-Archon-Column-188----Working-.doc

For some reason, EE would not upload the zip with the sample database, so I am attaching it separately.Working-with-Attachments--AA-188-.accdb

Basically, in the interface you just click on the control bound to an Attachment field, then click on the Manage Attachments icon in the little toolbar that appears over the control.  There you can add or delete the attachment file.
Avatar of Moshe Singer

ASKER

Thank you for your answer. However, I need to insert a letterhead/company logo etc. into all the reports that are generated from the software, as well as inserting this .jpg format letterhead/logo onto all statements, invoices, ID cards for members, etc. In the previous version, you were able to insert the actual .jpg file and it would insert it into all documents, however, here I am unable to insert the actual .jpg file and not just have  the system point to the file location where the .jpg file is stored.
Thank you for your answer. However, I need to insert a letterhead/company logo etc. into all the reports that are generated from the software, as well as inserting this .jpg format letterhead/logo onto all statements, invoices, ID cards for members, etc. In the previous version, you were able to insert the actual .jpg file and it would insert it into all documents, however, here I am unable to insert the actual .jpg file and not just have  the system point to the file location where the .jpg file is stored.
I forgot to include in my previous comment, that I need the .jpg inserted so that it can be displayed in all reports, statements. etc. In your sample database of Attatchments, I was not able to insert my graphic file and see it displayed.
Actually in the recent versions of Access is pretty easy to store images in a SQL server.
First you upload the image to the Database 
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
Dim mystream As ADODB.Stream

conn.connectionString = YOURConnectionString
conn.CursorLocation = adUseClient
conn.Open
 
'OPEN RECORDSET FOR WRITING
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

rs.Open "SELECT * FROM YourTable WHERE 1=0;", conn, adOpenKeyset, adLockOptimistic

Set mystream = New ADODB.Stream
mystream.Type = adTypeBinary
mystream.Open
mystream.LoadFromFile "Your's Image Path"
rs.addNew
rs.ImageData = mystream.mystream.Read
rs.Update


Then on an Event (e.g Load)
Me.ImageControl.PictureData = rs!ImageData

Open in new window

You should be able to place the logo in an Image control on a report -- no need to store it in a field.  For this type of situation, I generally make a report template with the logo and other standard formatting, and copy it as needed.
Thank you John Tsioumpris,
Your code seems to be a fantastic workaround.. I used your code with my type of connection, and I created a local table named "YourTable" and I made a field "ImageData" and the Data Type is OLE Object.

Set mystream = New ADODB.Stream
mystream.Type = adTypeBinary
mystream.Open
mystream.LoadFromFile strSql
rs.Edit
rs!ImageData = mystream.mystream.Read

when I run the above code, I get an error message on this last line of the code:
"Run-time error "438". Object doesn't support this property or method.

I look forward to hearing your explanation.
wrong copy/paste
rs!ImageData = mystream.Read

Open in new window


also this line maybe its better
Me.ImageControl.PictureData = rs!ImageData.Value

Open in new window


Check it and if you find any problem let me know..
thanks a million
there is no error massage
but it don't display the image
even if I click in the table it don't display the image
it is not "text" to test the contents, something is in field, but not the image
can you please help me
OK
Me!ImageControl.Picture = "Image Path"
brings in the image
but it didn't save the image
only if I open a recordset, and save it then it is fine

but if I replace it with a new image, it didn't change only if I close and reopen the form

can somone write a code to empty the mageControl before I bring in the new image
thanks in advence
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial