Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Picture in my report 34

Status
Not open for further replies.

strantheman

Programmer
Mar 12, 2001
333
US
Ive searched all of the Access forums, and I haven't found a solution that works. This seems like a very common procedure so im sure someone out there can help.

My ITEM table looks like this:

name | imagepath
-----------------------------------------------
Linksys Cable/DSL Router | d:\lsBEFSR41.jpg
Netgear Switch | d:\ngFS105.jpg

Name is the name of the product, and imagepath is where the photo is stored on my drive. My report pulls NAME, IMAGEPATH from ITEM table for the specified ID. I want to show the name of the product, and its corresponding picture on my report.

For this discussion, lets say the two objects on my report are named itemName and itemImage. I would assume this is as simple as setting some property of itemImage to the IMAGEPATH field, but ive been unable to figure this out. Please provide any help that you can. Id be willing to receive an email with a sample MDB file if thats what I have to do.

thanks in advance, im really hurtin here.
 
Well NorthNone I have no suggestions. Im sorry, but I just wanted to post and say happy birthday to this post. I started it a year ago for a program thats still being used every week, and this post is helping people still.

Hope scriverb can help you man.

see ya

 
actually, i got the solution for allowing it to grow and shrink, sort of.

Image is the box where the picture is inserted, ImageSize is a text field with the height I want it to grow (stays not visible), and ImagePath is a text box describing where to pull the data.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_Detail_Format

Me.Image.Picture = Nz(Me.ImagePath)
Me.Image.Height = Me.ImageSize

Exit_Detail_Format:
Exit Sub

Err_Detail_Format:
Resume Exit_Detail_Format

End Sub

The weirdest thing, however, is that now it'll show the correct picture corresponding to the record, but if a record doesn't have a shot, it'll just repeat the picture for the preceding record.

I can't figure it out. Help?
 
I haven't been on the site for the last few days so my emails have been piling up. But, I see that you found a solution. The problem that you posted about the picture from the last site staying there is probably because the old path is just staying in place. You aren't replacing it with anything. Why not create a .jpg image with some words of something that says No Picture Available or something similar. Then if the record doesn't have a shot direct the path to this picture. Just a thought.

Also, you could set the picture control .vislble property to False thus making in invisible to the user.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
that's pretty much what i've done, although it's a pretty inelegant solution.

the problem is that I want a 2" tall picture where applicable, and no picture (and no gap) where there is not photo. this solution leaves me with a 2" gap on all records.
 
The gap is there because the Detail Section is created X number of inches high. Why don't you try setting the Reports Detail Sections Can Shrink property to True. This will allow the section to shrink if data is blank.

Next, you could change the Sections Height promperty setting based upon whether the file was available for printing. You would have to toggle the height settings back and forth from short to tall depending on the availablility of the file.

Let me know if you have any questions about doing this.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Bob:
This is perhaps a little off the subject. but I have been following this thread with great interest, and can't help it, I have to ask..

What exactly does Me! ..... refer to?
I never understood it, perhaps because nobody explained it well. Is ME! synonym to "This FORM we are working on" or "this particular control" or what?

I am sure a lot of you out there will raise an eyebrow when you read this. I am obviously a newby, even though I have been learning Access 2k on my own for a while

Thanks

Luis
 
Exactly the same question that I asked when I first started with ACCESS. Me! stands for the current form or report that we are writing the VBA code in.

Me![ControlName] is the same as the long syntax version:

[Forms]![frmFormName]![ControlName]

or

[Reports]![rptReportName]![ControlName]

I hope this helps you to understand the syntax.



Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
thanks for your help on this. i'm beat now, but i'll get back to it on monday.
 
glenmac: Hope this posting was able to help you with your project. [2thumbsup]

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Sorry to pop into this...
Regarding relative paths to pictures: After thinking it over for some hours, it crossed my mind that the very folder where the back end resides would be the perfect place for... \images
And it has the advantage that anyone using the database should have write permissions in that folder.

Get the last "\" and you have the path. Add
"\" & images
and you have the images folder.
Store the 'relative path' as "\images\pic1.jpg"

Paste the following function in a module:

Code:
Function DbNamePath(Optional Opt = 0, Optional FilePath = "") As String
Dim strPath
Dim i As Integer
If FilePath = "" Then
strPath = DLookup("Database", "MSysObjects", "Database Is Not Null")
If IsNull(strPath) Then strPath = CurrentDb.Name
Else
strPath = FilePath
End If

For i = Len(strPath) To 1 Step -1
If Mid(strPath, i, 1) = "\" Then
Exit For4
End If
Next

Select Case Opt
Case 0
DbNamePath = strPath
Case 1 'just path
DbNamePath = Left(strPath, i)
Case 2
DbNamePath = Right(strPath, Len(strPath) - i)
End Select
End Function

'Opt' argument says what should be returned:
0 - entire string (path and file name)
1 - path (without file name)
2 - fileneme (no path)

FilePath: if not passed, the function attepts to set it to the back-end path. And if no backend, then the current database is used

The path to the images is evaluated as
DbNamePath(1) & "dbimages\imagename.jpg"

Bob mentioned it in one of these posts...I'll just re-iterate it: set the 'default' picture pointer in the form to a default 'noimage.jpg'. Otherwise you'llget a minor error when loading the form if the image doesn't exist.

Note. If the database is 'monolythic', the backend location is the same as the current database.

HTH

[pipe]
Daniel Vlas
Systems Consultant

 
danvlas: I really like this code. Thanks for updating this thread with your ideas. This thread seems to have really helpful to many as it keeps getting revisited. Have a star on me. Good code.
[2thumbsup]

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Message for scriverb:

I followed the instructions for adding an Image control along with the ImagePath field, and provided the code in the OnFormat Event on my report.

The good news is that the image specified in one of my records appears. The bad news is that the same image appears with every record. I'm not sure if it matters, but my report is based on a query, not a table.

Am I missing anything?

Thanks

 
I am having the exact same problem as the reply just before mine. My report is also based from a query.

Things I need help with. If the field is blank (path to an image) I need it to point to a specific picture.(A "no picture available" image) Also if it is a wrong path (if the image was deleted) I need it to point to the same "no picture available" image.

Is there a way to accomplish this.

Thanks
 
Sorry to come back to this thread after a year!

I have tried using the code posted by 'scriverb' on the second post.. and I seem to be getting an error when executing the report:

run-time error 2220

any idea why?
 
RealFlava: First of all to help you in the future if you to to ACCESS Help under Error Codes you will find the following Function that can be copied and pasted into a database module and then executed from a button on a form that will create a table of ACCESS error codes and their descriptions.

Code:
Function AccessAndJetErrorsTable() As Boolean
	Dim dbs As Database, tdf As TableDef, fld As Field
	Dim rst As Recordset, lngCode As Long
	Dim strAccessErr As String
	Const conAppObjectError = "Application-defined or object-defined error"

	On Error GoTo Error_AccessAndJetErrorsTable
	' Create Errors table with ErrorNumber and ErrorDescription fields.
	Set dbs = CurrentDb
	Set tdf = dbs.CreateTableDef("AccessAndJetErrors")
	Set fld = tdf.CreateField("ErrorCode", dbLong)

tdf.Fields.Append fld
	Set fld = tdf.CreateField("ErrorString", dbMemo)
	tdf.Fields.Append fld

	dbs.TableDefs.Append tdf
	' Open recordset on Errors table.
	Set rst = dbs.OpenRecordset("AccessAndJetErrors")
	' Loop through error codes.
	For lngCode = 0 To 3500
		On Error Resume Next
		' Raise each error.
		strAccessErr = AccessError(lngCode)
		DoCmd.Hourglass True
		' Skip error numbers without associated strings.
		If strAccessErr <> "" Then

' Skip codes that generate application or object-defined errors.
			If strAccessErr <> conAppObjectError Then
				' Add each error code and string to Errors table.
				rst.AddNew
				rst!ErrorCode = lngCode
				' Append string to memo field.
				rst!ErrorString.AppendChunk strAccessErr
				rst.Update
			End If
		End If
	Next lngCode
	' Close recordset.
	rst.Close
	DoCmd.Hourglass False
	RefreshDatabaseWindow
	MsgBox "Access and Jet errors table created."

AccessAndJetErrorsTable = True

Exit_AccessAndJetErrorsTable:
	Exit Function

Error_AccessAndJetErrorsTable:
	MsgBox Err & ": " & Err.Description
	AccessAndJetErrorsTable = False
	Resume Exit_AccessAndJetErrorsTable
End Function

Now as for Error 2220, this was is described as:
Microsoft Access can't open the file '|'.@@@1@@1

Does the code stop on a particular line of your VBA code? Please post your code and identify the line that is causing the problem.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Thanks for that Bob, I've managed to sort it ;)

If I want to add multiple pictures but under different field names, how would I do about doing that? I have tried many methods.. but can't seem to crack it.

I'm basically creating a Reporting tool, so I can just input the text into boxes on form and add supporting images. There 7 sections to the report - so each section will have different supporting images.
 
If you have 7 images for 7 controls on your report you could name the images all the same name with 1 thru 7 as a last character. This way you could store only one image name for the item and update your .Picture property with the path, imagename, and appropriate number for whichever section you are printing.

I am not sure if this makes sense but the best I can do with the limited info you provided. If I am off the mark please post back with a more detailed example so I can better understand you situation.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Thanks for that Bob.

more detailed:

Creating a database which will allow me to store details for my field visits and produce a report @ end using all the details I have inputted.

There are 7 sections (7 main headings) to the report where I'll write a few paragraphs under each heading, and want to add one or more pictures to illustrate more technical/complicated issues.

How would you suggest go about doing this? I have using OLE method - database file just grows! This method is fantastic, but not sure how to apply to this scenario.

Please help!

Thanks in adv
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top