473,320 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,320 developers and data experts.

Display images in your DB without using Attachment Fields

twinnyfo
3,653 Expert Mod 2GB
The later versions of MS Access have a field type called Attachment. This allows the user to "upload" documents and images into the database, so that all things are stored neatly in one place. However, as one advances in one's Access prowess, one finds that this new field types causes a few problems. One problem is that the size of your DB can grow significantly if you store a lot of documents in your Attachment fields. The second problem is that using an Attachment field isn't quite as straightforward as working with a regular text or number field. However, one thing that many users use Attachment field for is to display images on their forms.

This article provides an alternate method for displaying images associated with a record.

Let's say you have a Form frmCoolCars. Each record in your main Table tblCars has an image of the car associated with that record. Rather than uploading your image to the DB, you can save that image to a common location. For example, C:\Users\twinnyfo\Documents\DB\Cars\Images\. Create an additional text field in your table called CarImage. In that field, eneter the pull path and filename of your image: C:\Users\twinnyfo\Documents\DB\Cars\Images\Ferarri .jpg.

Now, just add an image control to your form (imgCar). Set the .PictureType Property to Linked, but make sure you do not include anything for the .Picture property. This comes later.

Now, in the OnCurrent Event of your Form, add the following code;

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. On Error GoTo EH
  3.  
  4.     Me.imgCar.Picture = Me.CarImage
  5.  
  6.     Exit Sub
  7. EH:
  8.     MsgBox "There was an error going to the current record!" & vbCrLf & vbCrLf & _
  9.         "Error: " & Err.Number & vbCrLf & _
  10.         "Description: " & Err.Description & vbCrLf & vbCrLf & _
  11.         "Please contact your Database Administrator.", vbCritical, "WARNING!"
  12.     Exit Sub
  13. End Sub
Nothing "rocket sciency" about this one, but just very useful.

Keep in mind that you're probably gonna wanna double-check a few things, like making sure the image exists, before you set the image file. You can also add code in your form to browse for image files and save that location/filename, and there would even be possibilities for adding multiple images for one record. BUT, this article is just a quickie on the basics--just in case you ever wanted to do something like this, so all the bells and whistles have been removed.
Jul 3 '18 #1
11 10461
zmbd
5,501 Expert Mod 4TB
Piggybacking from twinnyfo's article

This type of question comes up very often:
(One such thread)

One of my favorite ways of doing this is through a custom function that pulls the image location and feeds it into the form or document. I do this for my class roster - take a picture, store it on the drive, and the attendance form shows the student's mugshot - handy for the subs!
TO make this work, insert the image control and bind the control source to the function. Voila!


=fncPhotoIdLoc([ctrl_people_photo],"photoid")
[ctrl_people_photo] = the control name containing the image file's name
"photoid" = the directory where the images are located
The following code should clear this up...

This method also works very well in reports!

This is some of my older code - not as elegant as the stuff I write today; however, it works! By default I have an image directory under the directory the database is opened from... simple to modify it to use a table field and a dialog box to pull the photo location...
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function fncPhotoIdLoc(z_in_ctrlwfilename As Control, z_in_folderwphotos As String)
  5.     '
  6.     'I use the function directly in the control as the control source for text
  7.     'set the image control as linked and set the picture to this function.
  8.     'seems to work for functions and reports.
  9.     '=fncPhotoIdLoc([people_photo],"photoid")
  10.     '
  11.     Dim z_folderwphotos As String
  12.     Dim z_int As Integer
  13.     Dim z_ext As String
  14.     Dim z_currentdb_path As String
  15.     Dim z_photoid_path As String
  16.     Dim z_photoid_full As String
  17.     '
  18.     'error trap
  19.     On Error GoTo z_errortrap
  20.     '
  21.     'Get the current database - we'll need this for error trap
  22.     z_currentdb_path = CurrentProject.Path
  23.     '
  24.     'check for null/missing or wrong file type
  25.     If (z_in_ctrlwfilename.Value + "") = "" Then
  26.         Err.Raise 5
  27.     Else
  28.         '
  29.         'find out if the correct file extensions are being referenced
  30.         z_int = InStr(z_in_ctrlwfilename.Value, ".")
  31.         z_ext = Mid(z_in_ctrlwfilename.Value, z_int)
  32.         Select Case LCase(z_ext)
  33.             Case ".tif", ".tiff", ".gif", ".jpeg", ".jpg", ".png", ".bmp"
  34.                 '
  35.                 'good value - so do nothing.
  36.                 'Why use a select-case... because I dislike a ton of and/or's in if-then statements
  37.                 '
  38.             Case Else
  39.                 Err.Raise 5
  40.         End Select
  41.     '
  42.     End If
  43.     '
  44.     If (z_in_folderwphotos + "") = "" Then
  45.         Err.Raise 5
  46.     Else
  47.         z_folderwphotos = z_in_folderwphotos
  48.     End If
  49.     '
  50.     'do the location
  51.     z_photoid_path = z_currentdb_path & "\" & z_folderwphotos & "\"
  52.     '
  53.     'final path
  54.     z_photoid_full = z_photoid_path & z_in_ctrlwfilename
  55.     '
  56.     'determine if the file is available otherwise toss error
  57.     If Len(Dir(z_photoid_full)) = 0 Then Err.Raise 5
  58.     '
  59.     'return the path for the image
  60. z_resume_from_error:
  61.     fncPhotoIdLoc = z_photoid_full
  62. Exit Function
  63. z_errortrap:
  64.     '
  65.     'there's an error so set the value to my default error image
  66.     'Debug.Print Err.Number & " - " & Err.Description
  67.     z_photoid_full = z_currentdb_path & "\imgerror\_missing.jpg"
  68.     Resume z_resume_from_error
  69. End Function
and of course... the example database... it's currently in Access2013 - I do have an Acc2003 version if needed, the older versions are no longer supported - sigh
Attached Images
File Type: jpg FormDesignView.JPG (108.1 KB, 3110 views)
Attached Files
File Type: zip bytesthread_950020_pictures_in_reports.zip (556.4 KB, 381 views)
Aug 1 '18 #2
PhilOfWalton
1,430 Expert 1GB
As a matter of interest, there used to be a problem with images flickering as they loaded. Whether this was due to a much earlier version of Access/Windows, or slower processors, I know not.

What you had to do was change the registry settings. I believe there are a number of possible registry keys in Windows 10 including
Expand|Select|Wrap|Line Numbers
  1. HKEY_CURRENT_USER\Software\Microsoft\Shared Tools\Graphics Filters\Import\PICT\Options
  2.  
Expand|Select|Wrap|Line Numbers
  1. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Wow6432Node\Microsoft\Shared Tools\Graphics Filters\Import\JPEG\Options
  2.  
Expand|Select|Wrap|Line Numbers
  1. HKEY_USERS\S-1-5-21-210287491-3005076100-493087875-1001\Software\Microsoft\Shared Tools\Graphics Filters\Import\PICT\Options
  2.  
They all end with ShowFileDialog, and if you can find the correct one, that needs to be set to "No"

Phil
Aug 1 '18 #3
zmbd
5,501 Expert Mod 4TB
NB: Editing the registry is not for the novice, slight errors can render the PC unbootable to windows and beyond a novice's ability to repair.

1st thing to try if there are image flickering is to go into the image control's properties and set the tab stop to NO. Then reorder the Form's tab stops so that the image control is at the bottom of the series... at least that worked for me in Acc97 and newer.

There are a lot of reasons for the potential flickering... even tab controls
Allen Browne: Flicker with tab controls
Aug 1 '18 #4
PhilOfWalton
1,430 Expert 1GB
As I said, I am going back a long way, certainly to 32 bit computers and Windows 95 or windows 2000.

Yes, I certainly agree that one should be extremely wary of editing the registry, but in this case the clue is in the name "ShowProgressDialog".

I can't remember what happened, whether if set to "Yes", the picture revealed itself in stages, or whether some sort of timer was shown. Anyway, changing the setting to "No" meant that the whole picture appeared at once, although there was a small delay.

Phil
Aug 2 '18 #5
alorenzini
3 2Bits
This looks great but I would need to be able to add photos and comments and whatnot on like a frmPhotEdit and then when it is saved close that form and update your continuous form?

Art
Oct 7 '20 #6
twinnyfo
3,653 Expert Mod 2GB
Art,

Welcome to Bytes!

I'm not sure I understand your question. Could you describe your question a bit better. I think I am missing something.

Concerning the comments, All that should be part of the record the user is viewing. The record also contains a reference to the location of the photo.

Standing by to respond.
Oct 7 '20 #7
alorenzini
3 2Bits
Here I will attach a couple of pictures of what I am talking about. My issue is when I add a photo in frmUnitNoteDetail it will not display on my sfrmUnitNoteList.

Will I guess I don't know how to send you the pictures.
Oct 7 '20 #8
ADezii
8,834 Expert 8TB
How About Storing the Images as BLOBs?
http://bytes.com/topic/access/insigh...blob-not-movie
Oct 7 '20 #9
alorenzini
3 2Bits
We have thousands of photo so I think the DB would just become unmanageable after awhile. Not speaking of the size....
Oct 7 '20 #10
isladogs
455 Expert Mod 256MB
Hi alorenzini
Is this related to a very lengthy thread you posted at AWF where TheDBGuy assisted you?
Oct 7 '20 #11
twinnyfo
3,653 Expert Mod 2GB
And, what do you mean by adding a photo to your form? In design view? This article is about attaching photos programmatically using a reference in a table.

Thanks.
Oct 7 '20 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dafna m | last post by:
Please HELP 1. How can I display an array of images from diffrent types(jpeg, bmp..)(In C#) Can I also display video files?(In C#) *** Sent via Developersdex http://www.developersdex.com...
1
by: Mamatha | last post by:
Hi I am developing a small application to capture a record a video file through webcam in C#.NET. In this application i created a JPEG images for every slide,means every JPEG image was treated...
5
by: Yoramo | last post by:
Hello is it possible to display images on a ASPX without having them on the disk of the server ? I have images in a DB and whould like to display them on a web page. writing them to disk...
5
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page...
6
by: varojee | last post by:
hi! can we use any function to display our input without using a " printf " function? does c support such this possibilities? ...
2
by: rejidasan | last post by:
Hello All, I have a MFC Dialog based application. I am not using GDI or GDI+ libraries. I need to load PNG and JPEG images in this Dialog Based application. Can you suggest me how to to do...
8
pradeepjain
by: pradeepjain | last post by:
hii, I have 3 images for a single id like 00024 in the DB. when ever the user selects the ID from the drop down .all the 3 images must be displayed . how do i do this? this is the image...
3
by: markwillium | last post by:
Memo fields in MS Access are similar to the ‘text’ fields in that they allow you to store characters. However, the size of a text field is limited to just 255 characters while a memo field allows as...
3
by: BikeToWork | last post by:
I (foolishly) made a database with several attachment fields. Now, I want to get the values from those fields as a comma separated list, like the one that shows up in a query window under the name of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.