Avatar of clock1
clock1
 asked on

How to get and write the dimensions of images on hard drive into an Access table

Have 20,000 images in C:\pictures that contains 10GB of images of various sizes.
Have a table that contains a field named "Location" that lists path of each image.
Have created a field in same table named "Dimension".
Want to determine the aspect ratio of each image based on width x height.
How can I get and store in same table the dimension of each image without crashing Access?
Microsoft AccessVisual Basic ClassicDatabases

Avatar of undefined
Last Comment
Nick67

8/22/2022 - Mon
Nick67

Start here
https://www.experts-exchange.com/articles/13779/More-Fun-with-Really-Large-High-Fidelity-Images-in-Access-Reports.html

It's fairly straight-forward
Set a reference to WIA
'need a reference to MS Windows Image Acquisition 2.0 library

Dim rs as recordset
Set rs = CurrentDb.Openrecordset("Select * from Location;")

Create an Image object
Dim Img As WIA.ImageFile

Dim ThePath as String
ThePath= rs!ThePath

do unitl rs.EOF
     'Set it to a filepath
      Img.LoadFile ThePath

    With rs
         .Edit
         !Dimension = Img.Height/Img.Width
         .Update
    End with
    Set Img = Nothing
    rs.movenext
Loop

Make sense?
clock1

ASKER
Does rs!ThePath take the entire path listed in location?
ASKER CERTIFIED SOLUTION
Nick67

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
clock1

ASKER
Yes, contains legitimate file path.  I'll give it a try.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Nick67

Make sure you set the Reference!
The article has a working sample at the end of it.
clock1

ASKER
As I try this and read article, notice that author states cannot get 1000 images to work.  As stated in onset, I have 20,000 images.  But continuing to work.
Nick67

I am the author.
If you want to make 1000's PRINT on a report, well, yeah, that doesn't fly.
Processing 10's of thousands for length and width?  Piffle.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
clock1

ASKER
How do I earn Piffle when  I stated 20,000 images at beginning.  Sorry, no go solution.
Nick67

Sigh. YOU don't earn piffle.  The task at hand does :)

Getting a thousand jpgs to print on a report is VERY difficult for Access.
Getting Access to process 20K images for which you have fully qualified paths is child's-play for Access.
It'll be resource-intensive and take a bit, but eminently doable.
About 15-20 minutes or so for 20K files

Hence, piffle.

Sample attached.
This one takes 20K records from one table, finds if they exists and adds results to a second table.
Not quite what you are doing, but I am not altering production data for a sample!  You don't have my files, but the code and tables are tested and work.
piffle.mdb
clock1

ASKER
Opened mdb.  Clicked process. Expected to see dimension added to picture table.  What have I overlooked?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
clock1

ASKER
Disregard last comment from me.  Realize that images are on your location and no error checking in place.
Nick67

The error checking is in place -- but since fs.FileExists(ThePath) will return false in every case on your machine, that's the branch that runs, and no records get written.
Replace the data in tblPictures with valid data of your own and you are in business.
clock1

ASKER
Error checking as in MsgBox stating done appeared without error.  I'm good to try again.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Nick67

Going home for the weekend!
Hopefully, the code made sense to you.

Nick67
clock1

ASKER
Made sense.  Thanks, points are yours!
clock1

ASKER
Made sense.  Thanks, points are yours!
Your help has saved me hundreds of hours of internet surfing.
fblack61
Nick67

You're welcome!