Solved

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

Posted on 2016-09-19
10
183 Views
Last Modified: 2016-09-20
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.
0
Comment
Question by:Moshe Singer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 41805183
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.
0
 

Author Comment

by:Moshe Singer
ID: 41805257
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.
0
 

Author Comment

by:Moshe Singer
ID: 41805263
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.
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 17

Expert Comment

by:John Tsioumpris
ID: 41805265
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

0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 41805275
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.
0
 

Author Comment

by:Moshe Singer
ID: 41805416
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.
0
 
LVL 17

Expert Comment

by:John Tsioumpris
ID: 41805455
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..
0
 

Author Comment

by:Moshe Singer
ID: 41805498
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
0
 

Author Comment

by:Moshe Singer
ID: 41805560
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
0
 
LVL 17

Accepted Solution

by:
John Tsioumpris earned 500 total points
ID: 41805875
I guess this sample will solve your problems
New-Microsoft-Access-Database.zip
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
The goal of the tutorial is to teach the user the full work flow of how to use flash media encoder to stream onto YouTube.
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question