Linked pictures

Peter Bellamy

Registered User.
Local time
Today, 16:16
Joined
Dec 3, 2005
Messages
295
I have searched the forum but not found something that matches my requirement. I have FE BE networked db using A2003

Images are stored by users in a specific folder which is one level below the BE db. They name them with the reference number asociated with the item. For example DA2345. They are jpegs.

I want my form to display the image, if there is one, nothing if there isn't.

I need some code that checks for the existence of the jpeg so the code I have in the OnCurrent event can choose to not load it.

Has anyone got a suggestion?

Cheers
 
I'm sure I did this once with a bound object frame but I can't quite remember how...
 
Or you could just use the image object: have a field in your table that contains the path of your image, then in the on current of your form just put a bit of code in to say

Imageobject.picture=[Path_Field]

You might need to enclose in quotes to get it to work.
 
Thanks for replying

That is exactly what I have but it errors if there is no image. Not all records have associated images.

It is the checking code I am after !
Then I can make a button visible and that will open a form with the image on it.
 
Ah - well you could just do an on error goto, but that's a bit of a blanket statement. If you know that's the only error yu're going to get it should be OK.
 
This is a Function that caters for variable images. You will need to modify it as thge image directory [GetImageDir] can be variable. The Image File is on the form or Report as each stock item has an individual image. The image control is unbound.

Code:
Function GetPicture()
Dim FullPath As String
With CodeContextObject
FullPath = GetImageDir & .[ImageFile]
If Dir([FullPath]) <> Empty Then
.[ImageControl].Visible = True
.[ImageControl].Picture = FullPath
Else
.[ImageControl].Visible = False
End If
End With
End Function

The dir checks if the file exists and if is doesn't sets the ImageControl to being invisible.

Simon
 
Simon, that looks exactly what I want, thanks.
I am not familiar with "CodeContextObject" and reading the help file was not that clear.
My interpretation is, whereas Me represents the object that currently has focus, CodeContextObject is the object in which that code resides. Is that correct?

peter
 
CodeContextObject allows the Function to be independent of the Form or Report, in other words do not have to explicitly site the Form or Report. It's handy when you have numerous Forms all wanting to call the same Function, so instead of writing a script for each Form or Report you can use just one Function. The function is therefore reuseable.

Simon
 
So just to clarify Simon, If by using the code context you can place this code in a standard module, and as long as the control is resident on the calling form/report you do not need to explicitly refer to the form/report.
 
Better solution than mine but I reckon the mad kiwi is the winner
 
Having a dummy picture that states No picture available is infact a very good suggestion. At least it is informative, its lets the user know that there is no picture, and not that a picture may be there but for some reason it did not load.

Your dummy picture could be a slice of your screen image with the phrase "No Picture Available" embedded.
 
If only I could remember everything I read in this forum ! :rolleyes:
Thanks for the explanations

I have tried the code within the OnCurrent of my form substituting the name of my image

Code:
With CodeContextObject
FullPath = "Z:\Database\2000\Returns\images\" & Trim(Str(return_no)) & ".jpg"
'Debug.Print FullPath
If Dir([FullPath]) <> Empty Then
.[PartImmage].Visible = True
.[PartImage].Picture = FullPath
Else
.[PartImage].Visible = False
End If
End With

However it fails with error 13 type mismatch on the .[PartImage].Visible = False line ?

peter
 
Does it work if there is a picture to load? Ie the .visible = True
 
Sorry for duplicate, I thought the first entry did not post ??

David: Yes it does
 
If you consider the usage of the dummy image then both of these lines can be removed. You would replace the line with the link to the dummy image.

Code:
With CodeContextObject
If Dir([FullPath]) <> Empty Then
    FullPath = "Z:\Database\2000\Returns\images\" & Trim(Str(return_no)) & ".jpg"

Else
    FullPath = "Z:\Database\2000\Returns\images\Dummy.jpg"

End If
   .[PartImage].Picture = FullPath

End With
 
Sorry David I did not read your post properly :(
No it does not load if there is an image there, and has the same error.
 
If you are using an image control then you should be using this

.ImageControl.Picture = LoadPicture(FullPath)

Where .Imagecontrol is the name of the image control on the form.

I have taken thes from a VB form
 

Users who are viewing this thread

Back
Top Bottom