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!

Unwanted Repeating Images

Status
Not open for further replies.

Nitrous270

Technical User
Jul 27, 2002
67
US
I have a report that i am trying to make w/ different pictures on each record. I have the image path stored in a table. After searching through the forums I found this method of displaying the picture.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me![ImageFrame].Properties("Picture") = _
Me![ImagePath]
End Sub

This works and assigns a record the corresponding image, however if a record doesn't have an image it will use the last image and put it all of the following records.

I have tried puting in:

If Not IsNull(Me![ImagePath]) Then
<the statement above>
End If

It still has that problem though and likewise for the &quot;&quot; string.

Any Ideas?

Thanks,
Nitrous270


 
Okay Looking through the Northwind Database I found a way to display the image without repeating so here is my solution:

It consists of 4 fuctions the first one being located in the Detail_Format location. The other three are simply calls made within the Detail_Format function. Personally I put the IsRelative function in a module so that it could be used on a form as well.

As for the structure of my report. I have a text box containing the location of the image called ImagePath. I also have an object named Image where the Image is shown, I have an ImageBox the same size as the Image but is only shown when no image is avalible, and then I have a label called errormsg that displays &quot;Image Not Avalible&quot; when the Image is not present.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' Display the picture for the current record if the image
' exists. If the file name no longer exists or the
' file name was blank for the current employee, set
'the errormsg label caption to the appropriate message.

Dim fRes As Boolean
Dim strPath, strFName As String

strPath = CurrentProject.path

On Error Resume Next
errormsg.Visible = False
Me![ImageBox].Visible = False

If Not IsNull(Me![ImagePath]) Then
fRes = IsRelative(Me![ImagePath])
strFName = Me![ImagePath]
If (fRes = True) Then
strFName = strPath & &quot;\&quot; & strFName
End If

Me![Image].Picture = strFName
ShowImage
Me.PaintPalette = Me![Image].ObjectPalette

If (Me![Image].Picture <> strFName) Then
HideImage
End If
Else
HideImage
End If

End Sub

Sub HideImage()
' Hide the image control
Me![Image].Visible = False
Me![ImageBox].Visible = True
errormsg.Caption = &quot;Image Not Avalible&quot;
errormsg.Visible = True
End Sub

Sub ShowImage()
' Display the image control
Me![Image].Visible = True
Me![ImageBox].Visible = False
End Sub

Function IsRelative(FName As String) As Boolean
' Return false if the file name contains a drive or UNC path
IsRelative = (InStr(1, FName, &quot;:&quot;) = 0) And _
(InStr(1, FName, &quot;\\&quot;) = 0)
End Function
 
Nitrous270,

Sounds to me like you have a solution but here's a suggestion....Short and simple too....

Create an image for &quot;No Image Available&quot;...use paint or some graphic program. Make is anything you want. Me, I would create an image of the big circle with a slash and have &quot;No Image Available&quot; stamped accross it. Then, in the OnFormat of your details sections use:private Sub

Detail_Format(Cancel As Integer, FormatCount As Integer)
If IsNull([ImagePath]) Then
Me![ImageFrame].Properties(&quot;Picture&quot;) = insert path to no image picture you just created
Else
Me![ImageFrame].Properties(&quot;Picture&quot;) = _
Me![ImagePath]
End If
End Sub



Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top