How load pictures based on selected record

I am creating a two tab form.  On the first tab will be several fields that will autopopulate with data based on a record selection form a combo box on the to of the form (avove the tabs).  This is working fine.  But on the second tab I want .jpg pictures to display again based on the selection from the combo box.  Each record that can be selected has a path to a specific directory in one of the record fields.  So once the user selects a record, I would like to pictures in that specific directory to display on the 2nd tab on the form.  The can be up to 6 pictures for a given record so I have to limit the size of the loaded pictures to sort of a thumbnail view.  

How can I do this?
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Glenn_MooreCommented:
How are the pictures tied to the record?  Are they within the table fields?
0
SteveL13Author Commented:
The path to the pictures files is entered into a filed in the table.  Each set of pictures, tied to a specific record, is in a directory with the same name as the key field in the record.
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

There are lots of ways, here is one.

Drop an Image control (use the "Image" control from the toolbox) onto your desired sheet Tab.
Browse and point it to any random picture (Don't worry, we will change it later with code)
Do this for the other 5 images as well.

Change the "SizeMode" Property of all of these image controls to: "Zoom" (To keep the aspect ratio)
Resize the image controls to fit on the sheet

On the "Current" Event of your form put code like this:
Private Sub Form_Current()
    Me.TheNameOfTheFirstImageControl.Picture = Me.TheNameOfTheTextBoxThatContainsThePathToTheFirstImage
    Me.TheNameOfTheSecondImageControl.Picture = Me.TheNameOfTheTextBoxThatContainsThePathToTheSecondImage
    '....ect
End Sub

The data in my Path Fields looked something like this:
C:\Documents and Settings\MyProfile\My Documents\My Pictures\anderson.112702.jpg

My code ended up looking like this:
Private Sub Form_Current()
    Me.Image13.Picture = Me.txtPhoto1Path
    Me.Image14.Picture = Me.txtPhoto2Path
End Sub


Let me know how this works for you

JeffCoachman
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

SteveL13Author Commented:
Jeff,

I really like you answer.  But I have one issue I don't know how to deal with.  In reality, depending on the record the user selects on the main part of the tabbed form, the directory that the photos reside in will be different.  In other words I can't have a static path... it has to be changed for each selected record.  Plus, all 1-6 images will be in the same directory.  So lest say, just for example, the user selects record "111" from the combo box.  Then the image files all live in a folder on the hard drive named "111".  How can this be dealt with?
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

So you mean that for each record, only the path to a Folder is stored?

If so, all I can think of is that you use the "FollowHyperlink" command to open that folder directly in a Windows Explorer window.
Then if you change the View to "Thumbnails" (So you can see the images) it shoud stay that way when you open it again.

So on your forms current event you would put something like this:
    Application.FollowHyperlink Me.txtPhoto1Path

Let's see if another expert has any more insight.

JeffCoachman
0
SteveL13Author Commented:
Yes.. only the path that each of up to 6 pictures are located.  Somehow I have to figure out how to get all of up to 6 to load and display on the form.  Thanks for the help so far though.
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

I have seen these types of things done here actually.

Do a search here for: "Display images from Folder"
(Or something similar)

Good luck
;-)

JeffCoachman

(P.S.: what if there are 7 pictures?)
0
SteveL13Author Commented:
I did a little searching but couldn't really find any help.  I sure hope someone can figure this one out for me.
0
SteveL13Author Commented:
Just checking.. has anyone been able to think of a solution to this?  Would appreciate any feedback anyone can provide.
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

<as anyone been able to think of a solution to this?>
Still just me.
:)

...Boy, if this works, you owe me a beer!
(File was to big to upload)

;-)
0
Jeffrey CoachmanMIS LiasonCommented:
Here goes...

Considerations:
Be sure to set the DB to compact on close to minimized Bloat.
Investigate the following:
Linking to images instead of loading them
Storing images as "Blobs" instead of images
http://www.ammara.com/articles/imagesaccess.html (to mimimize bloat)

Study it carefully before you run it.

Let me know if you have any issues

JeffCoachman
Private Sub cboData_AfterUpdate()
' Find the record that matches the lookup combobox.
    Dim rs As Object
 
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[ID] = " & Str(Nz(Me![cboData], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
 
End Sub
 
Private Sub Form_Close()
'Clear out all the images to save disk space
    Call BlankOutImages
End Sub
 
Sub Form_Current()
'Presumptions:
'You have six image contols on your form
'With their Tag Properties set to 1-6 repectively
 
'Sync the lookup combobox to the form
Me.cboData = ID '<--Your Lookup Combobox
 
 
'If this is a new Recordset,
'blank out all the image controls, then exit
If Me.NewRecord Then
    Call BlankOutImages
    Exit Sub
End If
 
'Create the Variables
Dim bytCounter As Byte
Dim bytPicCount As Byte
Dim ctl As Control
 
Dim fso As New FileSystemObject
Dim jpgFile As File
Dim jpgFiles As Files
Dim Fldr As Scripting.Folder
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fldr = fso.GetFolder(Me.txtPhoto1Path) '<-- Your Textbox that stores the folder Path
Set jpgFiles = Fldr.Files
 
'Blank out any previous images from the previous record
Call BlankOutImages
 
'Set the number of Images to 6
bytPicCount = 6
'Start BytCouter at 1
bytCounter = 1
 
'-----Loop through the folder and load the "first" .jpg images into the contols
    'Do while the counter is less than or equal to the file picture count
    Do While bytCounter <= bytPicCount
        For Each jpgFile In Fldr.Files
        'If there are less than 6 images in the folder reset the Picture count
        If jpgFiles.Count < 6 Then bytPicCount = jpgFiles.Count
            If Right(jpgFile, 4) = ".jpg" Or Right(jpgFile, 5) = ".jpeg" Then
                For Each ctl In Me.Controls
                    'If the controls tag equals the counter value
                    If ctl.Tag = bytCounter Then
                        'Load the image file into the control
                        ctl.Picture = jpgFile
                    End If
               Next ctl
            End If
            bytCounter = bytCounter + 1
        Next jpgFile
    Loop
 
'Object Cleanup
Set jpgFiles = Nothing
Set Fldr = Nothing
Set fso = Nothing
 
End Sub
 
Sub BlankOutImages()
'Blank all images with Tag Properties  of 6 or lower
Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.Tag <= 6 Then
            ctl.Picture = ""
        End If
    Next ctl
End Sub

Open in new window

Image-Folder-Test-Setup.jpg
0
SteveL13Author Commented:
If this works I owe you a case of beer!  Am getting an error on...
Dim fso As New FileSystemObject

Also, I assume I need to setup 6 image controls, correct?

--Steve
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

<Am getting an error on...Dim fso As New FileSystemObject>
Oops, Sorry...
You have to add a reference to the "Microsoft Scripting Library" in the Visual Basic Editor.
In The VB editor, Click: Tools-->References
Scroll down and turn on: "Microsoft Scripting Library"
Click: OK
Click: Debug-->Compile (to check for any more errors.)

<Also, I assume I need to setup 6 image controls, correct?>
Yes, the "Image" control from the toolbox .
Like before, when you drop it in, just select any generic image, the code will change it anyway.
To be sure, name them img1, img2...ect
Set the Tag property of all them 1-6 respectively.

Keep me posted...

JeffCoachman
0
SteveL13Author Commented:
Jeff,

Hmmm. I don't have "Microsoft Scripting Library" in my list.  ?????

--Steve
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

Do you have "Microsoft Scripting Runtime"?... that will work as well.

Anyway, I just whipped up a sample here at work to test, and it works fine

https://filedb.experts-exchange.com/incoming/ee-stuff/6820-db4.zip

JeffCoachman

0
SteveL13Author Commented:
I turned that on and now get a new error...

Set Fldr = fso.GetFolder(Me.txtPath) '<-- Your Textbox that stores the folder Path

Please bear with me.  I'm learning.
0
Jeffrey CoachmanMIS LiasonCommented:
No problem,

"Me.txtPath" is the Name of the textbox that the Folder path is stored in.

It might be the same name as the field, but to be on the safe side, rename it to have a "txt" prefix.

So on your form, locate the textbox that displays the folder path.
Rename it to have a "txt" in front of it.
This new name is what goes on that line, in the parenthesis.
So yours will look something like this:
Set Fldr = fso.GetFolder(Me.txtYourFolderPath)

JeffCoachman

0
SteveL13Author Commented:
Jeff,

I do have it this way.  Would it be ok if I zip my mdb file and send it to you?
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

OK,

Use winzip to compress it (make sure it is less than 2MB)
Upload it to:
www.ee-stuff

JeffCoachman
0
SteveL13Author Commented:
Jeff,

I just uploaded it.  Never did that before with Experts.  I guess I thought it would show up here.  Let me know if I did somethng wrong.
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

Well.....

You had a lot of stuff going on here that I did not know about.
ex:
-Your form is Unbound.
-The textbox name is not similar to the Fields name
-You have some code on some After Update and current events that I don't know why it exists, so I commented them out.
-Why does it delete the values for the first record in the table???
-How are you moving from one record to the next?

How about this:
Take the first sample I sent you and set up a temporary folder setup like the screenshot I posted.
c:\Images
c:\Images\Old
c:\Images\New
...and load them with images

Verify that my sample DOES work.

Then, we can talk about modifying my sample to meet your specific requirements.

JeffCoachman

0
SteveL13Author Commented:
Jeff,

The way the form is to work is this...
1)  The user selects a record from the combo box.
2)  Depending on the record selected, thefield to the right of the combo box fills with data from the table, tblLots.  This information is for the user's reference only.
3)  Then also the field right under the combo box opens with a path to where the phots are.  This path is dependant on the "PhotoLoc" info again coming from tblLots.  There will be up to 6 images in any given folder.
4)  Depending on the 3rd character in the key field in tblLots, a tabbed form will be visible.  If it is a "C" then the Commercial tab should be visible.  If it is a "R" then the Residential tab will be visible.  In either case, the other tab is not visible.  That is probably all the other code you are talking about.  It does need to work this way.
5)  Then, and of course here is the catch...  depending on the path which has been autopopulated in the path field, the tab named "Photos" is to display the iamges in the folder related to the selected record in the combo box.

Any chance you can work with this?

--Steve
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

<Any chance you can work with this?>
I don't see any reason  why not.

I just want to make sure that my sample "Performs" the way you asked.
So once you get that going we can tweak your file.

Keep me posted on your progress

JeffCoachman
0
SteveL13Author Commented:
Jeff,

I loaded three image files into a C:Images folder and ran your form.  They loaded just fine.

Steve
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

Great!
Just wanted to make sure.

OK, thanks for the info on your form.
I'll have another look at it over the weekend.

JeffCoachman
0
SteveL13Author Commented:
Thank you, Jeff.  I really do appreciate all of your help.
0
SteveL13Author Commented:
Hi, Jeff.  Just wondering if you've had time to look at this any more.  

--Steve
0
Jeffrey CoachmanMIS LiasonCommented:
I got busy at work.

I am looking at it now
0
Jeffrey CoachmanMIS LiasonCommented:
SteveL13,

I still could not get a handlel on some of your code.
For example:
Why the form was unbound
Why the "Clear" button *Deleted" the values
Why the object name were not the same as the field names
...ect

So for the sake of submitting a "Clean" sample, I deleted these things
(They can always be added back in)

I added some validation and a few other tweaks as well

Let me know if this works for you

http://www.ee-stuff.com/Expert/Upload/getFile.php?fid=6865

JeffCoachman
0
SteveL13Author Commented:
I can't seem to download it.  I get...
"A download file with the given file name in the URL parameter could not be found. Please make sure that the file name is correct and the file exists in your download folder."
???
0
Jeffrey CoachmanMIS LiasonCommented:
Yeah, me too.
?

I'm at work now,
I will upload it again tonight, when I get home (approx 6PM EST)

Jeff
0
SteveL13Author Commented:
Thanks.
0
Jeffrey CoachmanMIS LiasonCommented:
0
SteveL13Author Commented:
??? Still doesn't work.  ????
0
Jeffrey CoachmanMIS LiasonCommented:
https://filedb.experts-exchange.com/incoming/ee-stuff/6871-Access--EEQ23150265.zip

I think either my name was to long or it does not like the Period (".") in the name.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
So you got it working in your app?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.