KB Article 210100 (Image From a Folder in a Form)

J

J. Trucking

Hello,

Just wondering if anyone has experience with this article. I have put
it into my DB but can only seem to ge the "NoPicture" picture to
display in my image control form instead of the actual picture. I
have checked the code and everything seems to be right (it must be
searching the right directory if it's finding the 'NoPicture'
picture). In each record that has a picture linked to it, it displays
the proper directory in the txtImageName text box. Some things that
could possibly be going wrong (but I dont know) might be: I'm using
JPEG's and not BMP's; the pictures are stored in a different directory
than the DB; The image frame has the properties of the image 'Linked'
and not 'Embedded'. Just wondering if anyone has ever tried this and
if they ran into the same problem as I am facing. Once again, the
'NoPicture' JPEG displays awesome...it just appears on every record,
even if the txtImageName text box displays a different picture/
directory.

Thanks in advance,

John
 
K

Ken Snell \(MVP\)

I use a similar setup in one of my applications, and it works fine. Post
details of the code that you're using and some example data from the table.
You are including the full path to the image files, correct? Show example
paths and file names.
 
J

J. Trucking

Hi Ken,

Thanks for the response.

I have a table called tblFleetInformation. This is where I store the
picture path, based on the Key of the table which is FleetID
(AutoNumber). I have a field called UnitPictureText (Text) to which I
put the path for each picture in its respective record with the full
pathname "F:\Johns Pics\Pictures\Units\130.jpg".

In the form itself, I have an image frame which I have labelled
"ImageFrame". I then filled in the 'picture' category on the
properties screen with a sample picture (F:\Johns Pics\Pictures\Units
\130.jpg). I also have a text box called UnitPictureText with the
control source also called UnitPictureText.

I then (as per the instuctions from the MS KB) clicked on the code
button for my form and typed in the following:

Function setImagePath()
Dim strImagePath as String
On Error GoTo PictureNotAvailable
strImagePath = Me.UnitPicturetext
Me.ImageFrame.Picture = strImagePath
Exit Function

PictureNotAvailable:
'I used a jpg (company logo) that will be called NoPicture to be used
when I dont have a pic for a particular unit
strImagePath = "F:\Johns Pics\Pictures\Units\NoPicture.jpg"
Me.ImageFrame.Picture = strImagePath
End Function

I then went into the OnCurrent and AfterUpdate Events of the form and
typed in =setImagePath()

When I open the form, I only get the 'NoPicture' picture for every
single record (it looks really good). For the records which I have
typed in the path for the actual picture (ie) F:\Johns Pics\Pictures
\Units\130.jpg.

So I'm assuming there is an error somewhere and it's automatically
going to the 'PictureNotAvailable' portion of the function. I just
cant figure out why.

John
 
J

J. Trucking

I'm also finding that some computers wont even show the image (I have
a front end/back end DB with an MDE). Could it be something with the
image editor?

John
 
K

Ken Snell \(MVP\)

Is the function setImagePath in the form's module, or in a regular module?
Do you have the UnitPicturetext field in the form's RecordSource query?

I don't use quite that approach. What I do is use VBA code in the form's
Current event procedure directly, instead of a function -- and in the box
next to On Current property, select "[Event Procedure]" from the dropdown
box. In this sample code, I've commented out the steps related to setting
strImagePath and you need to uncomment the code step(s) based on how your
form's RecordSource query is structured:


Private Sub Form_Current()
Dim strImagePath as String
On Error GoTo PictureNotAvailable

' use this next code step if UnitPicturetext field is in form's record
source query
' strImagePath = Me.UnitPicturetext

' use these next two code steps if UnitPicturetext field is not in form's
record source query
' strImagePath = DLookup("UnitPicturetext", "tblFleetInformation", _
' "FleetID=" & Me.FleetID.Value)

Me.ImageFrame.Picture = strImagePath
Exit SubPictureNotAvailable:
'I used a jpg (company logo) that will be called NoPicture to be used
'when I dont have a pic for a particular unit
strImagePath = "F:\Johns Pics\Pictures\Units\NoPicture.jpg"
Me.ImageFrame.Picture = strImagePath
End Sub
 
J

J. Trucking

Sorry I missed answering your questions. The function is in the
form's module, and no I dont have UnitPictureText in the form's record
source query.

Thanks,

John
 
K

Ken Snell \(MVP\)

J. Trucking said:
Sorry I missed answering your questions. The function is in the
form's module, and no I dont have UnitPictureText in the form's record
source query.


The absence of the UnitPictureText field from the recordsource query is the
cause of your problem when using the KB article's code.
 

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