Pictures in Forms (1 Viewer)

alexgore

Registered User.
Local time
Today, 11:01
Joined
Oct 10, 2012
Messages
17
Hi everyone.

The question I have is:
if I link a .jpg file to my form, will I be able to see the picture or will I just see the file path?

Scenario
I designed a database for our watch repairing company that is used to book every watch in that we receive. A picture is taken of the watch and uploaded as an attachment. (We print off the forms to accompany the watch around the workshop, and it's essential to have the actual picture).

It has all worked fine until now, when the database is corrupting frequently and the file size is pretty big.

In hindsight I now think I should have done a link to the picture rather than import them to keep the database a manageable size. :eek:

I have looked on previous posts on the forum to see if this is possible and it looks like it is. The answer I couldn't find was - if I link the .jpg file to the form, will I be able to see the picture or will I just see the file path?

I really appreciate your help with any suggestions. I'm a very inexperienced Access person but our business is relying on me getting it right! :eek:

Thanks, Alex
 

pr2-eugin

Super Moderator
Local time
Today, 11:01
Joined
Nov 30, 2011
Messages
8,494
Hello Alex, Linking a picture file to a record might be easier than you think.. And IMO, is the best way to go around rather than 'attaching'.. I have in the past helped another user (located at this thread) regarding a similar issue.. You might find a sample which might interest you as well.. Hope that helps..

If you have any troubles, post back.. :)
 

alexgore

Registered User.
Local time
Today, 11:01
Joined
Oct 10, 2012
Messages
17
Hi

Thanks so much for your reply. I've clicked on the link you suggested but it just comes up with a blank page?

Excuse my ignorance, but what does IMO stand for?

Thanks

Alex
 

pr2-eugin

Super Moderator
Local time
Today, 11:01
Joined
Nov 30, 2011
Messages
8,494

alexgore

Registered User.
Local time
Today, 11:01
Joined
Oct 10, 2012
Messages
17
Hi ya

I feel daft about IMO, I assumed it was Access Terminology!

I managed to open the link thanks, although it came up with a run time error 2220 (it can't open the png file).

Would this example work for a system where every access record has a unique picture?

Thanks for your help. I am above my head in this stuff!

Cheers, Alex
 

pr2-eugin

Super Moderator
Local time
Today, 11:01
Joined
Nov 30, 2011
Messages
8,494
To make it to work.. either you have to extract the contents of the ZIP Folder to C:\ Or change the linking in the Form.. You have to make modifications, but most definitely it will work for each and every record..
 

Simon_MT

Registered User.
Local time
Today, 11:01
Joined
Feb 26, 2007
Messages
2,176
Yes, the simple method is that an image relates to the RepairID.

On the form the easiest is to use a query the explicit location and Imagefile should be available and then is simply a matter of of telling the image control picture that it represents RepairID plus the extension of the image type.

It is unclear what version of Accesss you are using pngs it may require 2007+.

Simon
 

alexgore

Registered User.
Local time
Today, 11:01
Joined
Oct 10, 2012
Messages
17
Thanks for your reply Simon.

I'm using Access 2007. The images are .jpgs stored on the c drive. We are currently just writing the image name in a text box on the form, but ideally would like to have a link to the file so the picture shows.

Do you think this is possible in 2007?

Thanks

Alex:)
 

pr2-eugin

Super Moderator
Local time
Today, 11:01
Joined
Nov 30, 2011
Messages
8,494
So how far are you away from successfully making this work?
 

alexgore

Registered User.
Local time
Today, 11:01
Joined
Oct 10, 2012
Messages
17
Hi Paul

Not very far I'm afraid! I've just popped into work this morning and deleted all the pictures from the database, so hopefully now it's lovely and small that will stop it corrupting at least. I have created a text box in the meantime so the data entry lady can manually write the file name of the picture into it. (Just to keep the system working until I can get it changed if possible).

In all honesty I'm not sure what to do next. I would really appreciate any advise, especially in lay mans terms!

Thanks for your concern :)

(I've got to go offline now - the joys of childcare in the school holidays! - but will check back later)

Cheers,

Alex
 

Simon_MT

Registered User.
Local time
Today, 11:01
Joined
Feb 26, 2007
Messages
2,176
Alex:

I have all sorts of entties that have images in the main Stock. This is how I would go about:

ImagePath: Directory holding the Images
ImageFile: Actual File containing the image
ImageControl The only name used for any image Control

All the Images relate to a uniqueID:

I have already established the [Master] Directory for images:

C:\Images\

Artist: SUTTON Image: Artists\sutton.jpg
Exhibition: 10TS Image: Exhibitions\10ts.jpg
Original: 100347 Image: Originals\Sutton\100347.jpg
Print: 10077 Image: Prints\Sutton\10077.jpg
Book: 12NEWPOS Image: Books\12newpos.jpg

In each query I have a determined the ImageFile

[Artist Path] & [Artist] & ".jpg"
[Exhibition Path] & [Exhibition] & ".jpg"
[Original Path] & [Artist Images] & [Orig Old Stock] & ".jpg"
[Prints Path] & [Artists Images] & [Print Code] & ".jpg"

The reason there are multiple image directories is that there are 20,000 images is it needs a little organisation. You may not need this.

So now I use a Function to associate all the file elements [GetPicturePath], then call [GetPicture] OnCurrent / OnFormat:
Code:
Function GetPicture()

    With CodeContextObject

        If GetPictureExist = True Then
            .[ImageControl].Visible = True
            .[ImageControl].Picture = GetPicturePath
        Else
            .[ImageControl].Visible = False
        End If
    End With

End Function
I don't Specify file names / Collect file names.
After Update of Artist in Stock Entry the Image just appears.

Simon
 
Last edited:

pr2-eugin

Super Moderator
Local time
Today, 11:01
Joined
Nov 30, 2011
Messages
8,494
Alex,

It might look scary, but it is really simple.. Just focus on the following steps..

* Try getting into a proper naming convention for your Picture files.. What I mean by that is, every Client/Product will have its UNIQUE ID in the table (probably) the Primary key.. Use this as your picture file name.. If you have products as 175 then name the file as 175.jpg, this way, you do not have to use manual input.. which might go wrong at some point too.. and easier to handle in code..

* You can create a Form, with nothing on it except for an Empty picture frame into which we can use to display the file..

* Create a button that will have the code, something along the lines of..
Code:
Private Sub openPictureBtn_Click()
    DoCmd.OpenForm "pictureDisplay", OpenArgs:= Me.productID
* In the Form Open event you can set the picture frame, by using the OpenArgs..
Code:
Private Sub Form_Open(Cancel As Integer)
    Me.pictureImageFrame.Picture = "C:\" & Me.OpenArgs & ".jpg"
End Sub
This will the most simple and easy method.. You can set a default value by hardocding the Value as above C:\, if you wish you can also forward a path.. it all depends on how you wish to implement..

Please also note, that a proper Error handling procedure needs to be in place.. I have tried my best in creating this sample for you.. Post back if you have any troubles.. The sample contains Error handlers, and a dynamic Path generation.. as I mentioned, it can be hardcoded too..

Good Luck !!

EDIT: Seems like Simon, has given a solution too.. While my internet connection played up.. :)
 

Attachments

  • AlexSample.zip
    271.7 KB · Views: 174
Last edited:

Simon_MT

Registered User.
Local time
Today, 11:01
Joined
Feb 26, 2007
Messages
2,176
Alex:

Here is an example:

Simon
 

Attachments

  • Untitled-1.jpg
    Untitled-1.jpg
    79 KB · Views: 147

alexgore

Registered User.
Local time
Today, 11:01
Joined
Oct 10, 2012
Messages
17
Simon and PR2

Thanks very much for your time in trying to help me out. I have had a look at both examples you sent me an I think Simon's one would be better for us as it has the picture showing all the time.

I will try and have a go at Simon's version...

I appreciate your help.

Thanks, Alex:)
 

pr2-eugin

Super Moderator
Local time
Today, 11:01
Joined
Nov 30, 2011
Messages
8,494
I think Simon's one would be better for us as it has the picture showing all the time.
I am very mad !! :mad:

LOL.. Just kidding mate.. :D

I am glad you have sorted it out.. As you can see, "All roads lead to Rome !!".. At the end of the day it depends how you want to go..

Post back if you have some troubles.. Good Luck.. :)
 

Simon_MT

Registered User.
Local time
Today, 11:01
Joined
Feb 26, 2007
Messages
2,176
Alex

I do have a whole suite of functions to handle images. I need to manage images aspect, flags and size. I can post these as well

Simon
 

bigalpha

Registered User.
Local time
Today, 03:01
Joined
Jun 22, 2012
Messages
415
Alex:

I have all sorts of entties that have images in the main Stock. This is how I would go about:

ImagePath: Directory holding the Images
ImageFile: Actual File containing the image
ImageControl The only name used for any image Control

All the Images relate to a uniqueID:

I have already established the [Master] Directory for images:

C:\Images\

Artist: SUTTON Image: Artists\sutton.jpg
Exhibition: 10TS Image: Exhibitions\10ts.jpg
Original: 100347 Image: Originals\Sutton\100347.jpg
Print: 10077 Image: Prints\Sutton\10077.jpg
Book: 12NEWPOS Image: Books\12newpos.jpg

In each query I have a determined the ImageFile

[Artist Path] & [Artist] & ".jpg"
[Exhibition Path] & [Exhibition] & ".jpg"
[Original Path] & [Artist Images] & [Orig Old Stock] & ".jpg"
[Prints Path] & [Artists Images] & [Print Code] & ".jpg"

The reason there are multiple image directories is that there are 20,000 images is it needs a little organisation. You may not need this.

So now I use a Function to associate all the file elements [GetPicturePath], then call [GetPicture] OnCurrent / OnFormat:
Code:
Function GetPicture()

    With CodeContextObject

        If GetPictureExist = True Then
            .[ImageControl].Visible = True
            .[ImageControl].Picture = GetPicturePath
        Else
            .[ImageControl].Visible = False
        End If
    End With

End Function
I don't Specify file names / Collect file names.
After Update of Artist in Stock Entry the Image just appears.

Simon

I know this is kind of old, but looks like a good solution to what I'm doing. I can't quite piece it all together, though.

I created a query to combine the RecordPK (which is also how I'm going to name the pictures) with the rest of the path. So I end up with C:\Users\john.smith\Pictures\4.jpg in the query output.

I created a module with the GetPicture code and then called it from my report's On Current property.

I don't quite see how to link the query to the report and the code, though.
 

Simon_MT

Registered User.
Local time
Today, 11:01
Joined
Feb 26, 2007
Messages
2,176
I'll try the short version using C:\Users\john.smith\Pictures\4.jpg as Imagefile

Code:
Function GetPicture()

Dim FullPath As String

    With CodeContextObject
        FullPath = .[ImageFile]
        If Dir([FullPath]) <> Empty Then
            .[ImageControl].Visible = True
            .[ImageControl].Picture = FullPath
        Else
            .[ImageControl].Visible = False
        End If
    End With
End Function
Simon
 

Users who are viewing this thread

Top Bottom