Pictures in a form not blanking out if no path is included

L

Lila

I am using Access 2002. I have read the very helpful links provided in this
newsgroup, as well as used the Northwind database as my guide
http://support.microsoft.com/Default.aspx?id=148463

In fact, the form I used is based on the Employee form of the Northwind
database, but I added tabs across the top. On the second tab, I have 6
pictures that need to be shown. I have added the OnCurrent Event(s) to the
form, and the AfterUpdate event to the ImagePath(s).

The problem is this... I add the picture to the first record. I change to
the second record. The same picture shows up for the second record, even
though there is no picture defined in the ImagePath. I have hunted through
the events trying to locate an If statement that makes the original Employee
record display nothing in the ImageFrame when there is nothing defined in the
ImagePath, but I can't find it.

Any suggestions? Is it related to the tabs?
 
A

Arvin Meyer [MVP]

Unless the picture is changed in the Current event of the form, the picture
will always remain. You need something like this (air code):

Sub Form_Current()
If Len(Me.txtPath & vbNullString) > 0
Me.ImageControlName.Picture = Me.txtPath
Else
Me.ImageControlName.Picture = C:\Folder\Blank.jpg
End Sub

where Blank.jpg is a blank image or a default (I use one that says "No
Image") for instances where there is no path stored.
 
R

Rob Parker

Hi Lila,

If you are using the code from the Northwind Employees form in your
OnCurrent event, this should not be happening. The Northwind example hides
the image frame if there is no picture (via a call to Sub
hideImageFrame() ). Did you include this in your code?

If that's not the problem, please post the code from your Sub Form_Current()

Rob
 
L

Lila

I will definately give that a try, but I'm wondering if there is a way to
make it work without being dependant on a file. I noticed in the Northwind
database, they actually turned the image off by using:

hideImageFrame

If we could do that, would the following work?

Sub Form_Current()
If Len(Me.txtPath & vbNullString) > 0
Me.ImageControlName.Picture = Me.txtPath
Else
hideImageFrame
End Sub
 
L

Lila

Actually, the picture on the first tab works just fine. It's the 6 additional
pictures on the second tab that are having the problems. For those I added
the code indicated in the following link:

http://support.microsoft.com/Default.aspx?id=148463

The code is as follows. Note that the first section is straight from
Northwind and is fine. The last 6 are as noted in above link.


Private Sub Form_Current()
' 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 record, set the errormsg label caption to the
' appropriate message.
Dim res As Boolean
Dim fName As String

path = CurrentProject.path
On Error Resume Next
errormsg.Visible = False
If Not IsNull(Me!Photo) Then
res = IsRelative(Me!Photo)
fName = Me![ImagePath]
If (res = True) Then
fName = path & "\" & fName
End If

Me![ImageFrame].Picture = fName
showImageFrame
Me.PaintPalette = Me![ImageFrame].ObjectPalette
If (Me![ImageFrame].Picture <> fName) Then
hideImageFrame
errormsg.Caption = "Picture not found"
errormsg.Visible = True
End If
Else
hideImageFrame
errormsg.Caption = "Click Add/Change to add picture"
errormsg.Visible = True
End If
On Error Resume Next
Me![fabric1photoframe].Picture = Me![Fabric1Photo]
On Error Resume Next
Me![fabric2photoframe].Picture = Me![Fabric2Photo]
On Error Resume Next
Me![fabric3photoframe].Picture = Me![Fabric3Photo]
On Error Resume Next
Me![EdgeTrim Picture Frame].Picture = Me![EdgeTrim Picture Path]
On Error Resume Next
Me![FrameFinishFrame].Picture = Me![FrameFinishPicturePath]
On Error Resume Next
Me![HardSurfaceFrame].Picture = Me![HardSurfacePicturePath]

End Sub
 
R

Rob Parker

Lila,

You are not testing whether any of the other 6 pictures are missing, and
setting their frame states accordingly. You need to repeat the
If Not Isnull (Me!Photo) Then
...
End If
statements for each of your additional 6 picture fields, substituting the
appropriate field names and control names in each section of code.

You'll also need to either pass the control name to the showImageFrame and
hideImageFrame subroutines, or (probably easier) simply set the visible
property of each image frame control in the code in each If statement.
Using the second option, here's a sample of what each If ... End If section
will look like, using generic field/control names:

If Not IsNull(Me!NameOfPhotoField) Then
NameOfErrormsgControl.Visible = False
res = IsRelative(Me!NameOfPhotoField)
fName = Me![NameOfImagePathField]
If (res = True) Then
fName = path & "\" & fName
End If

Me![NameOfImageFrameControl].Picture = fName
Me![NameOfImageFrameControl].Visible = True
Me.PaintPalette = Me![NameOfImageFrameControl].ObjectPalette
If (Me![NameOfImageFrameControl].Picture <> fName) Then
Me![NameOfImageFrameControl].Visible = False
NameOfErrormsgControl.Caption = "Picture not found"
NameOfErrormsgControl.Visible = True
End If
Else
Me![NameOfImageFrameControl].Visible = False
NameOfErrormsgControl.Caption = "Click Add/Change to add picture"
NameOfErrormsgControl.Visible = True
End If

Also, a single On Error Resume Next statement (at/near the top of the Sub -
the current position is fine) is all that is needed (unless you change the
error handling). The statement (which stays in effect until a different On
Error Resume statement is encountered) simply says, in effect "if there's
any error when this code runs, ignore it and continue at the next line".
You might like to comment it out while you're changing your code, since it
will hide any errors that you might produce ;-)

I notice in your reply to Arvin's answer that you ask about not using a
file. The "file" is the pathname/filename of the picture that you are
using, stored in the NameOfPhotoField in your underlying table. You do need
it, in some fashion. Whether you need the particular code that's in the
Northwind example will depend on exactly what you are storing for each
picture; the code shown (which I haven't changed) will use the picture field
entry as an absolute pathname if it finds a drive designator or UNC path
designator in the picture field, otherwise it assumes that the picture
fields are defined relative to the folder of the database itself.

HTH,

Rob

Lila said:
Actually, the picture on the first tab works just fine. It's the 6
additional
pictures on the second tab that are having the problems. For those I added
the code indicated in the following link:

http://support.microsoft.com/Default.aspx?id=148463

The code is as follows. Note that the first section is straight from
Northwind and is fine. The last 6 are as noted in above link.


Private Sub Form_Current()
' 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 record, set the errormsg label caption to the
' appropriate message.
Dim res As Boolean
Dim fName As String

path = CurrentProject.path
On Error Resume Next
errormsg.Visible = False
If Not IsNull(Me!Photo) Then
res = IsRelative(Me!Photo)
fName = Me![ImagePath]
If (res = True) Then
fName = path & "\" & fName
End If

Me![ImageFrame].Picture = fName
showImageFrame
Me.PaintPalette = Me![ImageFrame].ObjectPalette
If (Me![ImageFrame].Picture <> fName) Then
hideImageFrame
errormsg.Caption = "Picture not found"
errormsg.Visible = True
End If
Else
hideImageFrame
errormsg.Caption = "Click Add/Change to add picture"
errormsg.Visible = True
End If
On Error Resume Next
Me![fabric1photoframe].Picture = Me![Fabric1Photo]
On Error Resume Next
Me![fabric2photoframe].Picture = Me![Fabric2Photo]
On Error Resume Next
Me![fabric3photoframe].Picture = Me![Fabric3Photo]
On Error Resume Next
Me![EdgeTrim Picture Frame].Picture = Me![EdgeTrim Picture Path]
On Error Resume Next
Me![FrameFinishFrame].Picture = Me![FrameFinishPicturePath]
On Error Resume Next
Me![HardSurfaceFrame].Picture = Me![HardSurfacePicturePath]

End Sub
 
L

Lila

Thank you for taking the time to reply. I will try this out at the office
tomorrow. I was hoping for just a few lines for each picture (like... if the
file name is null, hide the frame), but I guess it's necessary to do all of
the testing.

The file I was trying to avoid in the other post was hard coding a "none"
file. I'd hate to hard code a filename in the code. It would so easily break
everything if it was moved or deleted.

Lila
 
R

Rob Parker

Exactly how much code you need depends on exactly what your data looks like,
and whether you are wanting to display the "missing" message as in the
Northwind sample. For example, if your picture field has the full
path/filename for the picture, and you don't want any message displayed (are
happy with a blank space on your form), you could get away with something as
simple as this for each image control:

If Not IsNull(Me.NameOfPhotoField) Then
Me.NameOfImageFrameControl.Picture = Me.NameOfImagePathField
Me.NameOfImageFrameControl.Visible = True
Else
Me.NameOfImageFrameControl.Visible = False
End If

Note that if any of your field or object names contain spaces, you will need
square brackets around them. Note also that in this code I'm using all
dots, rather than a mixture of dots and bangs. In general, they are
interchangeable, and if you use dots you get intellisense while entering
code. My personal practice is to use dots everywhere except when referring
to recordset fields, when the ! is required. If you want to learn more
about that, search on the forms.coding group - there's regular discussion of
the topic.

Again, HTH,

Rob
 
L

Lila

I'm kind of new to this coding thing and I'm wondering if Me.NameOfPhotoField
is different from Me.NameOfImagePathField. In my table, I only have

a) a place to type in the name/description of the finish (i.e. Frame Finish)
that the user inputs

b) a place to store the image path (i.e. FrameFinishPicturePath) that the
user does not directly input (is changed with the code)

c) an image frame (i.e. FrameFinishFrame)

Thanks for the square bracket explaination. I'm wondering why do some use
"!" and some use a "." For example

Me![fabric2photoframe] as opposed to
Me.fabric1photoframe

Lila
 
L

Lila

My guess seemed to be right. It works great! Thanks a million!!!

If Not IsNull(Me.[Fabric1Photo]) Then
Me.[fabric1photoframe].Picture = Me.[Fabric1Photo]
Me.[fabric1photoframe].Visible = True
Else
Me.[fabric1photoframe].Visible = False
End If

Now if we can just get rid of that infernal file reload dialogue box that
crashes everything if you scroll through the items too quickly... Oh well!
Thanks again!

Lila said:
I'm kind of new to this coding thing and I'm wondering if Me.NameOfPhotoField
is different from Me.NameOfImagePathField. In my table, I only have

a) a place to type in the name/description of the finish (i.e. Frame Finish)
that the user inputs

b) a place to store the image path (i.e. FrameFinishPicturePath) that the
user does not directly input (is changed with the code)

c) an image frame (i.e. FrameFinishFrame)

Thanks for the square bracket explaination. I'm wondering why do some use
"!" and some use a "." For example

Me![fabric2photoframe] as opposed to
Me.fabric1photoframe

Lila

Rob Parker said:
If Not IsNull(Me.NameOfPhotoField) Then
Me.NameOfImageFrameControl.Picture = Me.NameOfImagePathField
Me.NameOfImageFrameControl.Visible = True
Else
Me.NameOfImageFrameControl.Visible = False
End If
 
R

Rob Parker

Hi Lila,

Standard problem, standard solution ;-)

You need to modify some registry keys to prevent this. The details are
available at
http://www.mvps.org/access/downloads/Set_ShowProgressDialog_To_No.reg

The easy way to incorporate these is this: Cut/paste to a text file (I used
Notepad), and save as a .reg file. Then all you need do is double-click the
file, or right-click and choose "Merge", to merge the entries into your
registry. For a 19kb file of entries, that's certainly faster than
entering them all manually ;-)

Note: there are more entries here than are actually needed to solve the
problem, but it's so easy to import the lot that it's not worth figuring out
exactly which ones you need (and, in my case, at one time some of the others
had been corrupted and I had a very weird problem - re-importing all the
keys cured it).

Glad to have helped so far, and HTH again,

Rob


Now if we can just get rid of that infernal file reload dialogue box that
crashes everything if you scroll through the items too quickly... Oh well!
Thanks again!
<snip>
 

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