Solved

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

Posted on 2016-09-19
10
64 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
  • 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
 
LVL 13

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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 13

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 13

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
The goal of this is to tech the user how to export photos out of Lightroom and the different options they have. Select which photos you want to export : Select where you want to export and with which options : Export :

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now