473,883 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
+ 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 16698
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
2037
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 that a mixture of PHP and MySQL would be a good idea. I have currently set up OmniHTTPd and installed MySQL and PHP onto my homeserver. I want the site to be set up as follows: 1- I add the report, date and pictures (and amount of pictures...
9
1966
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 Basic .Net application. I have researched MSDN for help and found the example article 321900 (see below) and set up a test and everything works fine when I use SQL Server 2000 but when I modify the code and use data from Access 2000 using an...
4
13043
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 picture. What am I doing wrong? Thanks,Lisa
4
7270
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 bank of questions allowing the user to create an exam by choosing the questions. Some of the questions have pictures for reference and some don't. I have chosen to keep the images in another folder with a test field (QPic) that contains the...
1
3041
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
10672
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 browse/add one picture at a time to a system. Now he would like to 'view' all of the thumbnails associated with any system on a single form. I can setup a main/subform scenario, but how do I show all of the pictures as thumbnails. I was using the...
12
20967
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 contains the paths to the pictures. The database consists of two tables: TABLE DATA ID Name LastName
1
1898
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
10114
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 best effort. Conditions: 80,000+ pictures (These are pictures of birds, ID by Species, Sex, Age, etc. (If known)) Hierarchy of folders: Continent->Country->State(if India, Mexico, USA, Canada, & Australia) (No state for other countries) I am...
0
9778
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11112
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10730
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10833
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5784
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3228
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.