Solved

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

Posted on 2016-09-19
10
50 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article will show you how to use shortcut menus in the Access run-time environment.
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
The goal of the tutorial is to teach the user how to use import presets downloaded from the internet into Adobe Lightroom. Once you downloaded the presets go into the preset folder and press import then import your preset and your set it to go.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

762 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

22 Experts available now in Live!

Get 1:1 Help Now