473,472 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Display Pictures in Access Report through VBA code

7 New Member
I have a form that is coded to open a File Dialog boc to pick a picture to display on that particular item on a subform. My form is not based on query, but rather two separate tables (one primary, one sub). That code is working properly. How do I get that to translate to my report? I use VBA code because I use formats other than BMP for the pictures. Would basing the form on the qury that the report is based on solve the issue without further coding? Below is the code from the form.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Dim path As String
  4.  
  5. Private Sub AddPicture_Click()
  6.     ' Use the Office File Open dialog to get a file name to use
  7.     ' as an employee picture.
  8.     getFileName
  9. End Sub
  10.  
  11. Private Sub Form_RecordExit(Cancel As Integer)
  12.     ' Hide the errormsg label to reduce flashing when navigating
  13.     ' between records.
  14.     errormsg.Visible = False
  15. End Sub
  16.  
  17. Private Sub RemovePicture_Click()
  18.     ' Clear the file name for the employee record and display the
  19.     ' errormsg label.
  20.     Me![ImagePath] = ""
  21.     hideImageFrame
  22.     errormsg.Visible = True
  23. End Sub
  24. Private Sub ImagePath_AfterUpdate()
  25.     ' After selecting an image for the employee, display it.
  26.     On Error Resume Next
  27.         'showErrorMessage
  28.         showImageFrame
  29.         If (IsRelative(Me!ImagePath) = True) Then
  30.             Me![ImageFrame].Picture = path & Me![ImagePath]
  31.         Else
  32.             Me![ImageFrame].Picture = Me![ImagePath]
  33.         End If
  34. End Sub
  35. Private Sub Form_Current()
  36.     ' Display the picture for the current employee record if the image
  37.     ' exists.  If the file name no longer exists or the file name was blank
  38.     ' for the current employee, set the errormsg label caption to the
  39.     ' appropriate message.
  40.     Dim res As Boolean
  41.     Dim fName As String
  42.  
  43.     path = CurrentProject.path
  44.     On Error Resume Next
  45.         errormsg.Visible = False
  46.         If Not IsNull(Me!Photo) Then
  47.             res = IsRelative(Me!Photo)
  48.             fName = Me![ImagePath]
  49.             If (res = True) Then
  50.                 fName = path & "\" & fName
  51.             End If
  52.  
  53.             Me![ImageFrame].Picture = fName
  54.             showImageFrame
  55.             Me.PaintPalette = Me![ImageFrame].ObjectPalette
  56.             If (Me![ImageFrame].Picture <> fName) Then
  57.                 hideImageFrame
  58.                 errormsg.Caption = "Picture not found"
  59.                 errormsg.Visible = True
  60.             End If
  61.         Else
  62.             hideImageFrame
  63.             errormsg.Caption = "Click Add/Change to add picture"
  64.             errormsg.Visible = True
  65.         End If
  66.  
  67. End Sub
  68.  
  69. Sub getFileName()
  70.     ' Displays the Office File Open dialog to choose a file name
  71.     ' for the current employee record.  If the user selects a file
  72.     ' display it in the image control.
  73.     Dim fileName As String
  74.     Dim result As Integer
  75.     Dim fd As FileDialog
  76.     Set fd = Application.FileDialog(msoFileDialogFilePicker)
  77.     With fd
  78.         .Title = "Select Screenshot"
  79.         .Filters.Add "All Files", "*.*"
  80.         .Filters.Add "JPEGs", "*.jpg"
  81.         .Filters.Add "Bitmaps", "*.bmp"
  82.         .Filters.Add "Portable Network Graphics", "*.png"
  83.         .FilterIndex = 4
  84.         .AllowMultiSelect = False
  85.         .InitialFileName = CurrentProject.path
  86.         result = .Show
  87.         If (result <> 0) Then
  88.             fileName = Trim(.SelectedItems.Item(1))
  89.             Me![ImagePath].Visible = True
  90.             Me![ImagePath].SetFocus
  91.             Me![ImagePath].Text = fileName
  92.             Me![Issue Reference].SetFocus
  93.             Me![ImagePath].Visible = False
  94.         End If
  95.     End With
  96. End Sub
  97.  
  98. 'Sub showErrorMessage()
  99.     ' Display the errormsg label if the image file is not available.
  100.     'If Not IsNull(Me!Photo) Then
  101.      '   errormsg.Visible = False
  102.     'Else
  103.      '   errormsg.Visible = True
  104.     'End If
  105. 'End Sub
  106.  
  107. Function IsRelative(fName As String) As Boolean
  108.     ' Return false if the file name contains a drive or UNC path
  109.     IsRelative = (InStr(1, fName, ":") = 0) And (InStr(1, fName, "\\") = 0)
  110. End Function
  111.  
  112. Sub hideImageFrame()
  113.     ' Hide the image control
  114.     Me![ImageFrame].Visible = False
  115. End Sub
  116.  
  117. Sub showImageFrame()
  118.     ' Display the image control
  119.     Me![ImageFrame].Visible = True
  120. End Sub
  121.  
  122. Private Sub CloseForm_Click()
  123. On Error GoTo Err_CloseForm_Click
  124.  
  125.  
  126.     DoCmd.Close
  127.  
  128. Exit_CloseForm_Click:
  129.     Exit Sub
  130.  
  131. Err_CloseForm_Click:
  132.     MsgBox Err.Description
  133.     Resume Exit_CloseForm_Click
  134.  
  135. End Sub
  136. Private Sub Rpt_Click()
  137. On Error GoTo Err_Rpt_Click
  138.  
  139.     Dim stDocName As String
  140.  
  141.     stDocName = "Print Test Report"
  142.     DoCmd.OpenReport stDocName, acPreview
  143.  
  144. Exit_Rpt_Click:
  145.     Exit Sub
  146.  
  147. Err_Rpt_Click:
  148.     MsgBox Err.Description
  149.     Resume Exit_Rpt_Click
  150.  
  151. End Sub
Dec 5 '07 #1
2 16602
Denburt
1,356 Recognized Expert Top Contributor
What kind of control is Me![ImagePath] and is it bound to a field in the table? If it is bound to a field in the table you should be able to include that in your query that is behind the report then bind it to your control in the report.

What kind of control are you trying to bind to in the report and what have you tried so far in that respect?
Dec 5 '07 #2
smorrison64
7 New Member
What kind of control is Me![ImagePath] and is it bound to a field in the table? If it is bound to a field in the table you should be able to include that in your query that is behind the report then bind it to your control in the report.

What kind of control are you trying to bind to in the report and what have you tried so far in that respect?
I am not binding it because as I understand it bound can only support .bmp files and I'm using multiple formats.

The file name is being stored in the Steps table which is part of the query on which the report is based. I just want to display in an image control the picture associated with the step, if there is one, for that particular step in a process.

I've tried using pieces of the code from above and adapting it to the report but I'm not having any luck.
Dec 6 '07 #3

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

Similar topics

0
by: JakeC | last post by:
Hey all, I'm currently redesigning a website that a friend and I started about a year ago. It is a daily surf report so when choosing the best script/language to use for the new design, I found...
9
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
4
by: Lisa | last post by:
Hello, I have an ole object in my database that contains mostly pictures. I have this field in a report that I need to export to MS Word. When I export the report, I get everything accept the...
4
by: Dale Ring | last post by:
Access 2000 I am trying to print a report that only some of the records have pictures. When the report prints, I do not want a blank image control showing on the report. This project is a test...
1
by: Majstor | last post by:
Does anybody know how to export Report in Word, Excel or HTML with pictures (Access 2000)? I don't use snapshot format.
3
by: RAllsopp | last post by:
I have a client who would like to have several pictures associated with one system. I have read about storing only the pathname to save OLE overhead and have set-up a form for my client to...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
1
by: JDW | last post by:
Now I have a picture in a Form and each record has a different picture. How can I add this pictures in a Report ? JDW Belgium
46
by: OldBirdman | last post by:
What a mess this question is. I have spent 2 weeks trying to make it concise and clear, and I can't. I do not have the vocabulary for the question. I cannot even TITLE it correctly. Here is my...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.