Code problem - Displaying Images

G

Guest

I am working with Access 2003. I am new to programming and I have a table
with 6 text fields which has paths to images. I want the images to show up
in my report opened. There are 6 image controls(one for each image field)It
is working somewhat, but it seems that when I scoll through the records it
will show the previous image if there is no image to show for that particular
image control. Below is my code. Any suggestions?

Option Compare Database
Option Explicit

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

If Not Me!East_Picture_Before = "" Or Not IsNull(Me!East_Picture_Before)
Then
Me!Picture1.Picture = GetPathPart & Me!East_Picture_Before

Else
Me!Picture1.Picture = ""
End If

If Not Me!East_Picture_After = "" Or Not IsNull(Me!East_Picture_After)
Then
Me!Picture2.Picture = GetPathPart & Me!East_Picture_After

Else
Me!Picture2.Picture = ""
End If

If Not Me!West_Picture_Before = "" Or Not IsNull(Me!West_Picture_Before)
Then
Me!Picture3.Picture = GetPathPart & Me!West_Picture_Before

Else
Me!Picture3.Picture = ""
End If

If Not Me!West_Picture_After = "" Or Not
IsNull(Me!West_Picture_After) Then
Me!Picture4.Picture = GetPathPart & Me!West_Picture_After

Else
Me!Picture4.Picture = ""
End If

If Not Me!Additional_Picture1 = "" Or Not IsNull(Me!Additional_Picture1)
Then
Me!Picture5.Picture = GetPathPart & Me!Additional_Picture1

Else
Me!Picture5.Picture = ""
End If

If Not Me!Additional_Picture2 = "" Or Not IsNull(Me!Additional_Picture2)
Then
Me!Picture6.Picture = GetPathPart & Me!Additional_Picture2

Else
Me!Picture6.Picture = ""
End If

exit_Detail_Format:
Exit Sub

err_Detail_Format:
MsgBox Err.Description
Resume exit_Detail_Format
End Sub


Private Function GetPathPart() As String
' Comments : Returns the path part of a string
' Parameters: strPath - string to parse
' Returns : path part

Dim db As DAO.Database
Dim strPath As String
Dim intCounter As Integer

Set db = CurrentDb
strPath = db.Name
db.Close
Set db = Nothing

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

GetPathPart = Left$(strPath, intCounter)

End Function
 
G

Guest

Here is example from a form (linked image files, form has field with image
full name such as xyz.jpg), and may suggest a solution for you.


mStrImage = gStrImagePath & Nz(ImageFileName)
'gStrImagePath is set to folder that contains all the images
'ImageFileName is image name, a field in each record


If Dir(mStrImage) = Nz(ImageFileName) Then 'the specific image exists
lblNoImage.Visible = False
'this is a label on top of image control
'it can say something like "No Image Available"
'in this case we hide the message since we have an image

imgProduct.Visible = True
imgProduct.Picture = mStrImage
'if we have an image, set it
'mStrImage is fully qualified path, for example "C:\Images\xyz.jpg"


Else
'we have nothing to show, hide the image control, so the message label
imgProduct.Visible = False
lblNoImage.Visible = True
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top