Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-09-19
10
Medium Priority
?
629 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 19

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 19

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 19

Accepted Solution

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

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

916 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