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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a dynamic image to a form. 1

Status
Not open for further replies.

piperent

Programmer
Feb 7, 2002
156
US
Is it possible? I have a table of vehicles. For each vehicle, there is a field (cell) which holds the 'folder\image-name.jpg' (e:\shared\anyvehicle.jpg) for that vehicle's picture. Is there a way to pick up that image and display it on a form? I know PHP does this with the help of a browser plugin, but I don't know that Access has that same type of functionality.

Thanks

JP
 
How are ya piperent . . .

Yes you can but be aware you can only do this in [blue]single form[/blue] . . . [purple]not continuous form[/purple]. Also be aware the identifying field needs to contain the full [blue]Drive:\Path\FileName[/blue].
[ol][li]Add an [blue]Image Object[/blue] to the form by clicking
ImageObj.BMP
then clicking where you want it in the form.[/li]
[li]Next, in the [blue]Current[/blue] event of the form, copy paste the following:
Code:
[blue]   If Trim(Me![purple][b]PathFieldName[/b][/purple] & "") = "" Then
      Me![purple][b]ImageCtlName[/b][/purple].Picture = ""
   Else
      Me![purple][b]ImageCtlName[/b][/purple].Picture = ![purple][b]PathFieldName[/b][/purple]
   End If[/blue]
[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
Sorry for the delayed response. Been tied up on another issue. I tried this little snippet of code and I must have missed something somewhere. When I try to insert an image object, it wants me to load a specific file. Is that correct? My assumption is that you load some default image file, then this routine over-rides that file if there is a name in this field.

I'm sure there is something I am doing wrong, but it comes back and gives me an 'Invalid syntax or unknown file or field value' then puts me in the debugger. That's probably the last place they want me to be. But, I'll keep at it.

Thanks,
I'll post back any success stories.

JP
 
piperent said:
[blue]My assumption is that you load some default image file . . .[/blue]
Yes thats correct. Initially you have to select a picture to set the image control. After that you delete whats in the [blue]Picture[/blue] property and save the form to lock it in.

Now . . . this is how it works:
[ol][li]When the form is first opened or the user navigates to a different record, the [blue]On Current[/blue] event is triggered.[/li]
[li]Code in the event checks your [blue]Path Field[/blue]:
[ol a][li]If the [blue]Path Field[/blue] is null/empty, the Picture property of the Image control is set to a null string (no picture).[/li]
[li]If the [blue]Path Field[/blue] has data, the Picture property is set to that Path & FileName contained in the [blue]Path Field[/blue] (picture appears).[/li][/ol][/li][/ol]

In te code snippit, [blue]you![/blue] substitute proper names in [purple]purple[/purple]. To be sure, look to the [blue]Name[/blue] property.

Finally:
piperent said:
[blue]For each vehicle, there is a field (cell) which holds the [purple]'folder\image-name.jpg' [/purple](e:\shared\anyvehicle.jpg) . . .[/blue]
Wrong! . . . these have to be changed to a full [purple] Drive:\Path\FileName specifier[/purple] for each picture, such as:
[blue]C:\Pictures\Birds\Sparrow.jpg[/blue]

Thats it . . . let me know how you make out . . .


Calvin.gif
See Ya! . . . . . .
 
Finally got this to work. Just like the 'Aceman' says. Took me a bit to figure out what substituted as what, but it works just fine.

Thanks, and sorry it took so long to get back to it.

JP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top