Resize Images
By Richard Rost
3 years ago
Resize Images in Access Using FFmpeg & Paint
In this Microsoft Access tutorial, I'm going to teach you how to resize images directly from your Access database. We'll cover two distinct methods for achieving this. First, we'll explore how to use the Shell function in VBA to run FFmpeg, an open-source multimedia handling utility. Next, for those who prefer an approach that doesn't require 3rd-party software, I'll guide you through a technique using SendKeys and Microsoft Paint. This tutorial is designed for both Advanced users and Developers, offering a practical way to manipulate images within Access.
Maya from Eagan, Minnesota (a Silver Member) asks: How can I resize large, high-resolution JPEG files from my photographers to a more manageable size, like 500 pixels across, so that I can easily link them to my Microsoft Access database?
Members
There is no Extended Cut, but here's the database for the Gold members.
Silver Members and up get access to view Extended Cut videos, when available. Gold Members can download the files from class plus get access to the Code Vault. If you're not a member, Join Today!
Prerequisites
Links
FFmpeg
Recommended Courses
Keywords
access 2016, access 2019, access 2021, access 365, microsoft access, ms access, ms access tutorial, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #learn, #lesson, #training, #database, resize images in access, resize pictures, ffmpeg, shell, sendkeys, Access VBA Image Resize, Image Manipulation Access, Scale Images Access Database, Access Image Control, VBA Code Image Resize, Batch Resize Access, MS Access Image Optimization, VBA Picture Resize
Subscribe to Resize Images
Get notifications when this page is updated
Intro In this video, we'll learn how to resize images for use in Microsoft Access. I'll show you two practical methods: one using the free third-party tool FFMPEG to easily scale images to a specific width, and another using Windows Paint and VBA with SendKeys for those unable to install additional software. We'll look at how to integrate these resizing methods with your Access database, set up error handling, and properly refresh your image controls after making changes. This tutorial is ideal if you need to manage high-resolution photos in your Access applications for reports or forms.Transcript Today we're going to learn how to resize images inside of Microsoft Access. I'm going to show you two different methods. One, using FFMPEG, which is a third-party image and video utility. It's free. And a second method using the built-in Windows Paint, which is not the best way but if you do not want to use any third-party software, it will work.
Today's question comes from Maya in Egan, Minnesota, one of my Silver members. Maya says, how can I resize large high-resolution JPEG files from my photographers to a more manageable size like 500 pixels across? I can easily link them in my Microsoft Access database.
I used to deal with this problem a lot. You get high-resolution photos, some of them 20, 30, 40 megabytes, and they're gigantic. You put them into a report, and it just takes forever for the report to generate. Most of the time, I used to use images in my database just to put product photos on my website. You do not need those huge photos on a website.
So what we're going to do is take whatever image you get and scale it down so it's nice and small. You do not need something that's 5,000 pixels across. Just bring it down to 500. We can do this right inside of Microsoft Access. Now, Access by itself does not have the built-in tools to manipulate image files. Neither do Word, Excel, PowerPoint, or any of the other Office applications.
You could do something inwardly. You can load an image and then resize it and then save the document. But you can't re-save that picture. You can't export the picture out of it. So the best way to do it is to use a third-party utility. Normally, when it comes to Access development, I try to stay away from third-party utilities unless it's something that you absolutely cannot do with Access. This falls into that category because Access is powerless to do it.
While doing my research for this video, I found some other programs. There they are right there on the screen. I have not used any one of these, but if you are a user of these different utilities, go right ahead. You'll have to look up the command-line parameters to see how to do it, but that's beyond what I'm going to show you.
I'm going to show you how to use FFMPEG. Now, this is a video editing application that's been around for years. In fact, I used to use this extensively for video editing and splicing. It's free and it's open source. I'll put a link to it down below where you can get your copy. It's very easy. You do not even have to install anything. You just get an EXE file and we're going to call that from Access. And that's it.
Back in the early 2000s, when I started my tutorial business, I used to record with different software than I use today. It recorded and created AVI files, and so I used FFMPEG to convert those over into MP4 files. But the nice thing about FFMPEG is it also works with images. You can use it to convert from one image type to another or to do things like resizing, cropping, scaling, all kinds of different stuff.
Today, I'm just going to show you how to resize an image. But you can dig into the documentation. You'll find there's tons of different things you can do with it.
For those of you in a workplace where they do not allow any third-party software whatsoever, I'm going to show you a second technique. It's not as reliable. We're going to use Windows Paint and SendKeys. Yes, we can open up Paint to open up your image. Then with SendKeys, we can send the right key combination to resize it and save it. It's cheesy, but it works.
Alright, so first up, some prerequisites. If you have not yet watched my images video, make sure you go watch this. If you have watched it, you know that we do not store images inside of our Microsoft Access database. No, no, bad, bad, bad. You do not do that. It makes your database file big and bloated. Do not do that.
What we do is save the filename to where that image is, and then we can display it with the image control. That's what I show you how to do in this video. Go watch this first. In fact, I'm going to use the database that I built in this video to show you this stuff today.
Of course, we're going to use a bunch of VBA programming today. If you've never done any VBA programming, go watch this video. It's about 20 minutes long and it will teach you everything you need to know to get started. We're going to use a little bit of error handling in case we run into an error while we run the FFMPEG software. Go watch this video on error handling and some basic debugging tips. These are all free videos. They're on my website. They're on my YouTube channel. Go watch them and come on back.
Alrighty. I'm going to start off by grabbing a copy of the database that I built in the images video. Since I'm a Gold member on my own website, I can do this. It's pretty weird if I was not, right? Alright, so we've got the images database. We've got an images folder underneath the database. Open it up. There we go. We have our customer form, and here's the path and filename for this person's, this handsome devil's, profile picture. There's another one there.
Now, if we take a look at the images, open them, these ones are already pretty reasonably sized at 500 by 531. Let's say we want to just scale these down to maybe 300 pixels across. So how do we do that? Well, we go get a copy of FFMPEG. It's at FFMPEG.org. Go there. You'll see a download button here.
The only thing you can download directly from their site is this download source code. That means you get to download it and compile it and do all that stuff, but there are packages people have already put together for you in Linux, Windows, Apple. Just come down here. There are two different sites you can go to get the EXE files. Pick either one of them. I'll put links to these down below, by the way. You can just go click on those.
Alright, here's this site. Just come on down until you find the release build. Just get the essentials one. There's the FFMPEG release essentials. Once you get that, right-click and extract it. In here, you'll find the only file you need is in the bin directory, and this guy right there, FFMPEG.exe, that's the only file you need. Like I said, there's nothing to install. This is a classic, top-level utility. It's really nice. I'm just going to take this and drop it in my images folder. Okay, so we have FFMPEG.exe in my images folder, and now we can go back to our database.
I'm going to come in here, right-click, design view, and let's just copy this guy. This was in the extended cut, by the way, I showed you how to browse for a photo instead of having to type the whole thing in. Another reason to become a member.
Alright, resize. Let's right-click. Actually, let's give it a name first. I always forget this step. Call this resize button. Right-click, build event, and open up a code builder.
Start off with some variables. We're going to need source file as a string, destination file as a string, new width as a long, and FFMPEG to put its location as a string.
So we're going to start off with source file equals whatever the profile picture is. Destination file is going to be profile picture plus a 2 at the end of it. So it'll be whatever.jpg2. I know it's not a valid name, but when we're done, we're going to rename it back to the source file. Or, to make this non-destructive, let's keep it as it is. We'll leave the original alone. In fact, let's just do this: .2.jpg, like this. The end of the file will be mypicture.2.jpg.
You could go through proper renaming of it and all that. This is just easy code for class.
Now, FFMPEG is going to be equal to the full path of the executable, which in my case is going to be this with FFMPEG.exe on the end of it. So it's going to be that.
Let's set our new width equals 300, and I spelled new width wrong.
Now, we need some error handling - on error resume next - for this part, because we're going to kill the destination file if it already exists. If this .2.jpg is already there, delete it.
For the next part, I want to know if there's an error message. So we're going to say on error go to myerrorhandler, and that'll be down here at the end. I'm going to message box error and whatever that error was, error description. Then we're going to resume. Always resume out of an error block like this. This will simply be exit sub right there. So if there is an error with the next code here, it's going to jump down here, tell you what the error is, resume, and then exit out. If there is no error, it's going to finish and exit out here. That's how I do that.
Next up comes shelling out to run FFMPEG. The FFMPEG command line is going to look like this. If you were just typing this at the command prompt, you would type in FFMPEG. That is the name of the program. .exe is assumed, you don't need that. /i means that's the input, and there's the filename, input.jpg.
Next up is this command, which is -vf, which stands for video filter graph. It basically says you're going to be manipulating the input video or image with a filter graph. What's a filter graph? It just means you're resizing, cropping, rotating, whatever.
This is what you're actually doing: setting the scale to however many pixels wide, and then :-1 means keep the aspect ratio. So if it's 4 by 3, it'll be 600 by whatever that number turns out to be. Little math says 450. If it's 1028 by 768, it's going to keep that aspect ratio. You can change this if you want to, you'll skew it. You can make it like 600 by 200, but then it will get stretched.
This here, -q:v, specifies the quality. This is a number from 1 to 31 with 1 being the best. So if you have JPEGs, for example, you can set that to a higher number, like 10, 15, 30, but it will make the file size smaller, though the image will get grainier. So keep it at 1 if you want to keep all the quality of the original image, which usually you do.
Finally, you have your output.jpg. That's the output file.
We have to take this and translate it into a proper command that we can use with Shell. This is what that looks like. I'm not typing it again, I already typed it in once today.
It's Shell, the basic Shell command to run another program. Here's the call to ffmpeg.exe, whatever we have up here in our variable. The reason why I have this inside of quotes is because if you have a space anywhere in there, like Desktop, you need to have that. I don't, so I don't need it, but it's good to have in case this changes in the future.
There's the /i, here's the source file, the -vf scale, new width:-1, the -q:v, all that stuff, destination file goes here, and vbNormalFocus so we can see it. You can change this if you want so that it's hidden. You do not have to see this window pop up. I like it, personally, because I like to see the window in case there is an error message inside of FFMPEG.
If you want to learn more about the Shell function and how it works, I do have an old tip video on my website. I'll probably re-record this in the near future, but this one works and it shows you how it works.
At this point, we should have a file called whatever.2.jpg in our hard drive and folder. What we're going to do is set the profile picture now equal to the destination file. So we're going to say profile picture equals destination file and then Me.Refresh. We'll let the user know with a message box "Done" or you can use my status box or whatever you want to use. Then that's it. It will exit out and everything's fine. If it did not work, it will exit out with an error.
Let's save it and see if it works. Give it a quick Debug > Compile. Everything looks good. Come back out here, open it up. Ready? Hit the resize button. Done.
I noticed FFMPEG ran on my other screen because this is not my primary monitor, but it did run. It just flashes real quick and then goes away. I like to see the window just in case there's an error message in FFMPEG. You'll see it instead of Access just going, oh no, it's going on.
Let's take a look at what it did. First of all, notice here our picture disappeared. I'm going to explain why in a minute. Come back out here and notice there's your .2.jpg. Notice that it's 300 pixels across. It did put the file in there, and watch, if you leave and come back to it, look, it's there. We just have to refresh this manually, that's all.
Let me show you how to do that in a second. Same thing with this one. Ready? Hit it. Click. Done. Check this. There's that guy. 300 pixels across again. Perfect. Leave it and come back to it.
This is an issue. A standard Me.Refresh does not repaint this guy. You do not want to require the whole form because it will reload all the records. So, what do we do? There is a trick. If you want to get this picture to reload, just make the control invisible and then visible again and it will show. I know it's a cheesy trick, but that's what you have to do.
Come back over here and do it after the message box: ProfilePictureImage (that's the control that has the picture in it).Visible = False The same thing again right after that: = True That's a little hack, and it works.
Ready, let's do it again. Let's change this back to the original. Delete. Ready, resize. It works, and then their picture comes back. When you make something invisible and visible again, it forces Access to redraw it on the screen. Repaint does not work. Requery works, but it requires all the records and puts you back to the beginning.
You know what I haven't tried is a recordset.Requery. Let's see if that works. Let's try that. Let's do Me.Recordset.Requery. That requerifies the records underneath but leaves you on the current record wherever you are. Doing a little experimentation today. Maybe this might be easier.
Ready. Go. Done. That worked too. There we go. Good. I'm not going to use the visible/invisible thing anymore. You can use recordset.Requery. I have a separate video on that too, I'll put a link to it down below.
Basically, Me.Requery reloads all the records in this form. In this case, all six customers, but it puts you back at the beginning. Recordset.Requery requerifies the underlying records but leaves the cursor where it is, and in this case, on record two. That's handy as well. That appears to work here. Either of those methods will work fine. You can either redraw the picture by making it invisible and visible again, or do a recordset.Requery.
Now, I need another cup of coffee.
For those of you who are locked in IT nightmare hell where you can't do any changes to your computer or install any third-party applications or your corporate virus scanner is going to catch FFMPEG and then you're going to get fired, you can send them to me. I'll tell them where to go.
Yes, you can do this with Windows Paint. It's not a very elegant solution. It uses SendKeys. Let me show you how that works as well.
Let's get rid of this stuff in here. Let's make these guys go back to their originals. Delete them out of here.
Essentially, every copy of Windows comes with Paint. I have heard some rumblings that they are going to be getting rid of Paint in future versions of Windows. Who knows if that's true.
What we're going to do is open up your picture in Paint, which can handle JPEGs and all that. Let's pretend this is your picture. Once the application is open, we're going to send it some keys. We're going to use my SleepSeconds function that I have another video on. I'll put a link to that down below as well. I also have videos on SendKeys. I'll put links to that as well.
Essentially, we're going to send it Ctrl+W, which opens up the Resize and Skew dialog. Then we have to tab three times: tab, tab, tab to Pixels. Press the space bar to select that. Tab again, set the width to 300, and then press Enter. That resizes it. Hit Ctrl+S to save it. This is a destructive save, so it's going to save over the file because it will have a name. When you send it this way, it will save over the original.
So if you want to, in your VBA code, copy the original and make a backup file of it first, perhaps. When that's all done, we're going to send Alt+F4 to quit. You will not get the save dialog because your image will just have been saved.
Let's look at the code. Design view. Let's make this "ResizeFFMPEG" and we'll make another one "Resize with Paint." VSizePaintButton. Right-click, build event.
We need the same variables: source file, destination file, new width. We do not need FFMPEG because we're going to be using Paint, which is part of Windows and should be in the path.
Set up error handling as in the previous routine.
We're going to FileCopy our source file to the destination file first so we do not lose our original. Remember I said before it's going to be destructive.
Now we're going to Shell Paint. That's going to look like this: Shell "mspaint.exe" with the file name and path and all that stuff. We're going to open the destination file. vbNormalFocus again so we can see it.
Now we wait. You have to give it at least two seconds. On a slower computer, you might have to wait a little longer. SleepSec 2
Now, what is SleepSec? This is an older database. This isn't the newest TechHelp free template. In the new one, I have a global module with some basic functions like Sleep in it. Let me go grab a copy of that real quick. Copy the global module into this one.
Global module has a function called SleepSec, which sleeps for a number of seconds. I have a whole separate video on that too.
Back in here, we're going to open up Paint, wait at least two seconds for it to load, then send keys Ctrl+W. Make sure you use a lowercase 'w'. If not, you're sending Ctrl+Shift+W, which is not the same thing.
After that, wait a bit. You don't need to wait a complete second, so just call Sleep and make it 300 milliseconds, like a third of a second. If you send the key presses one after another immediately, they tend to sometimes clog up like a traffic jam. I like to put a little delay between key presses.
Now, more of the same. SendKeys Tab, Tab, Tab and then Space to tab to 'Pixels' and select it; wait; tab again to horizontal width; wait; SendKeys the new width (300); press Enter; Ctrl+S to save it; Alt+F4 to quit; beep; message box 'Done.' That's it.
Save it, Debug > Compile, everything looks good. Set the profile picture = destination file when done, and then do Me.Recordset.Requery so it reloads and refreshes.
Now, resize with Paint and go. You can see this one working with SendKeys. Done, and it reloads. Do the next one for the other picture and it works as expected.
If you like this stuff, if you like learning VBA with me, if you enjoy my teaching style, check out my developer lessons available on my website. I think I'm up to 44 now. I'm teaching pretty much everything there is to know about Microsoft Access. If I do not have a video on it already, I'm probably going to make one pretty soon. Let me know if you have any questions or things you want to see in Access that I don't already have a video for.
If you do a Google search about something Access related and you do not see one of my videos there, I want to know so I can make one and fill that gap of knowledge.
But that's it. That's going to be your TechHelp video for today. I hope you learned something, my friends. Live long and prosper. I'll see you next time.
To find additional resources and links, YouTube does a pretty good job of hiding it. Right down there in the description, under the video title, there's a little 'Show more' link. Click on that and you'll see a list of other videos, additional information related to the current topic, free lessons, and lots more.
YouTube no longer sends out email notifications when new videos are posted, but if you'd like to get an email every time I post a new video, click on the link to join my mailing list. You can pick how frequently to get emails from me: as they happen, daily, weekly, or monthly.
If you'd like to become a paid member of my channel and receive all kinds of awesome perks, click on the Join button. You'll see a list of all the different membership levels that are available, each with its own special perks, including my extended cut videos, access to my code vault, lots of VBA source code in there, template downloads, and lots more. I'll talk more about these perks at the end of the video.
Even if you do not want to commit to becoming a paid member but you'd like to help support my work, please feel free to click on the tip jar link. Your patronage is greatly appreciated and will help keep these free videos coming. I have some puppies to feed. But don't worry, no matter what, these free TechHelp videos are going to keep coming. As long as you keep watching them, I'll keep making more. And they'll always be free.
If you really want to learn Access and you have not tried my free Access Level 1 course, check it out now. It covers all the basics of Microsoft Access, including building forms, queries, reports, and more. It's over four hours long. You can find it on my website or on my YouTube channel. I'll put a link down below you can click on. Did I mention it's completely free? The whole thing: free, four hours. Go watch it.
A lot of you have said you do not have time to sit through a four-hour course, so I now have a quicker Microsoft Access for Beginners video that covers all the basics faster in about 30 minutes. No, I did not just put the video on fast forward. I'll put a link to this down below as well.
If you like Level 1, Level 2 is just a dollar. That's it, one dollar. It's another whole, like, 90-minute course. Level 2 is also free for paid members of any level, including Supporters. If you are a member, go watch Level 2. It's free.
Want to get your question answered in a video just like this one? Visit my TechHelp page and send me your question there. Members get priority, of course. While I do try to read and respond to all of the comments posted below in the comments section, I only have time to go through them briefly a couple of times a month, and sometimes I get thousands of them. Send me your question on the TechHelp page and you'll have a better chance of getting it answered.
While you're on my website, be sure to stop by my Access Forum. We've got lots of lively conversations about Microsoft Access and other topics. I have a fantastic group of moderators who help me answer questions. Shout out to Alex, Kevin, Scott, Adam, John, Dan, Wan, and everybody else who helps on the site. I appreciate everything you do. I could not do it without you.
Be sure to follow my blog, find me on Twitter, and of course on YouTube. I'm on Facebook too, but I do not like Facebook.
Now, let's talk more about those member perks if you decide to join as a paid member. There are different levels: Silver, Gold, Platinum, and Diamond.
Silver members get access to all of my extended cut TechHelp videos, one free beginner class every month, and some other perks.
Gold members get all the previous perks plus access to download the sample databases that I build in my TechHelp videos, plus access to my Code Vault, where I keep tons of different functions that I use and the code that I build in most of the videos. You'll also get higher priority if you do submit any TechHelp questions.
Answers are never guaranteed, but you do go higher in the list in my algorithm, and if I like your question, you've got a good chance of it being answered. You also get one free expert level class each month after you've finished the beginner series.
Platinum members get all the previous perks plus even higher priority for TechHelp questions. You get access to all of my full beginner level courses for every subject, and I cover lots of different subjects like Word, Excel, VBA, ASP - not just Access. These are the full-length courses found on my website; you get all the beginner ones. Once you finish the expert classes, you get one free developer class per month, so lots of training.
Finally, you can also become a Diamond sponsor. You'll have your name or your company name listed on a sponsors page that will be shown on each video as long as you're a sponsor. You'll get a shout out in the video and a link to your website or product in the text below the video and on my website.
So that's it. Once again, my name is Richard Rost. Thank you for watching this video brought to you by AccessLearningZone.com. I hope you enjoyed it. I hope you learned something today. Live long and prosper, my friends. I'll see you again soon.Quiz Q1. What is the main reason for resizing high-resolution images before using them in Microsoft Access reports or on websites? A. To increase their visual appeal B. To reduce file size and improve performance C. To change the file type for compatibility D. To increase the image quality
Q2. Why should you avoid storing actual image files inside a Microsoft Access database? A. It makes it easier to share the database B. It provides better security for images C. It keeps the database file small and prevents it from becoming bloated D. It allows Access to edit the images directly
Q3. Which method does NOT require third-party software to resize images for use in Access, according to the video? A. Using FFMPEG B. Using Windows Paint with SendKeys C. Using Access's built-in image manipulation tools D. Using proprietary software like Photoshop
Q4. What is FFMPEG primarily known for, aside from image resizing? A. Spreadsheet calculations B. Video editing and conversion C. Text file encryption D. Database backup utilities
Q5. In the example shown, what does the command line argument -vf scale=300:-1 do in FFMPEG? A. Sets image width to 300 pixels and ignores height B. Sets image height to 300 pixels and ignores width C. Sets image width to 300 pixels and keeps aspect ratio D. Sets image quality to 300 on a scale of 1 to 1000
Q6. When using FFMPEG to resize images in Access, why is the filename put in quotes in the Shell command? A. To specify the file is a JPEG B. To ensure paths with spaces work correctly C. To indicate a hidden file D. To force the file to be an output
Q7. What does the -q:v 1 parameter within an FFMPEG command specify? A. Output file location B. Width of the image C. Quality of the output image (1 is best) D. Height of the output image
Q8. What is the problem with using Me.Refresh to reload an updated image in an Access form? A. It closes the form B. It re-queries all records and loses the current record position C. It does not repaint the image control D. It permanently deletes the original image
Q9. Which of the following solutions were suggested to force Access to reload an updated image control? A. Use Me.Close and Me.Open B. Use Repaint or requery the whole form only C. Toggle the control's Visible property or use Me.Recordset.Requery D. Rename the image file
Q10. What must you be wary of when using the Windows Paint and SendKeys method for resizing images? A. It always increases the file size B. It is non-destructive to the original image by default C. It overwrites the original image unless you create a copy first D. It only works for PNG images
Q11. What important step is added in the Paint/SendKeys method to avoid losing the original image? A. Converting to BMP format B. Sending Alt+Delete before resizing C. Copying the file before opening it in Paint D. Using Save As instead of Save
Q12. Why is it suggested to use short delays (Sleep) between SendKeys actions in VBA automation? A. To avoid image corruption B. To give Paint time to process each key and avoid command overlap C. To reduce CPU usage D. To increase image quality
Q13. Which approach is most robust and recommended for resizing in a professional environment when allowed? A. Editing by hand in a graphics editor B. Using FFMPEG via command line or shell call C. Using only Microsoft Paint D. Printing out images and scanning them back
Q14. According to the video, what is true about linking image files in Access? A. The image file must be embedded for best performance B. Only images under 100KB will display C. Storing the file path in the database and displaying it using an image control is preferred D. Images must be converted to PDF first
Q15. What is the purpose of using error handling in the VBA procedures demonstrated? A. To prevent sending duplicate emails B. To gracefully manage problems when running FFMPEG or manipulating files C. To automatically compress all files in the folder D. To restrict access to certain users
Answers: 1-B; 2-C; 3-B; 4-B; 5-C; 6-B; 7-C; 8-C; 9-C; 10-C; 11-C; 12-B; 13-B; 14-C; 15-B
DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks.Summary Today's TechHelp tutorial from Access Learning Zone is all about how to resize images for use in Microsoft Access. I will explain two effective ways to handle this: one method uses FFMPEG, which is a free, third-party utility typically known for video editing but also works very well for image tasks. The second method takes advantage of Windows Paint, which does not require any additional installations, and is useful if you want to avoid third-party software altogether.
The reason this comes up is simple: often, photographers or suppliers provide very large, high-resolution JPEG files that are way too big for everyday database tasks or web use. Such huge files can slow Access reports to a crawl and burden your system for no good reason. In most cases, you only need an image that is a few hundred pixels wide for reports or websites. Shrinking these down to a width like 500 pixels makes everything more manageable.
First, let me clarify that Microsoft Access itself does not come with built-in tools to resize images. The same is true for other Office programs such as Excel, Word, or PowerPoint. While you can insert and manipulate images within documents, these programs do not let you simply export or save downsized versions of those images. Because Access cannot do this natively, we need to turn to outside utilities. Normally, I avoid third-party solutions unless absolutely necessary, but this is one of those exceptions.
Before we get started, make sure you have watched my previous video on how to properly store images in Microsoft Access. I strongly advise against storing image files directly inside your Access database, as this can quickly bloat the database and cause performance problems. The best approach is to save the image file separately and store just the filename or its path in your database. The image control in Access can then display the image as needed. I will also be using VBA for this process, so if you are new to programming with VBA, I recommend brushing up with my introductory lessons and error handling tutorials, which are free on my website and YouTube channel.
To begin, I am starting with a copy of the database I built for my images tutorial. My images are stored in a designated folder and linked to records in the database. Let's suppose we have some images currently sized at 500 by 531 pixels but want to reduce them further, say, to 300 pixels in width. Here is how to do it using FFMPEG:
FFMPEG is a free, open-source utility that you can find at ffmpeg.org. While it is most famous for handling video conversions, it works with still images too, allowing you to convert formats, resize, crop, and more. When downloading, you do not need to install anything, just grab the executable file. Place ffmpeg.exe in your images folder or somewhere accessible.
Within your Access form, you can set up a button to handle the resizing. Assign your variables such as the source file, the destination file (I suggest adding a ".2" before the file extension so you do not overwrite your originals), your desired new width, and the path to ffmpeg.exe itself. Add appropriate error handling in your VBA. When you shell out to FFMPEG, you'll use command-line arguments to specify the input file, apply a scaling filter to set the width (keeping the aspect ratio by specifying -1 for the height), set the output quality, and generate the resized image.
Once this is done, update your form to use the newly created image. Occasionally, Access might not immediately refresh the displayed image. There are two ways to force a reload: you can toggle the visibility of the image control off and on, or, as I discovered while recording this tutorial, you can use Me.Recordset.Requery to requery the current recordset without causing the form to lose its place. Either approach will cause Access to redraw the image so you can immediately see the updated file.
Of course, not everyone is allowed to use third-party software in their workplace. For those environments, there is a second, somewhat clunkier option: Windows Paint, which comes with every version of Windows. This method uses the SendKeys function in VBA to automate the resizing process inside Paint. You open the image in Paint with a Shell command, wait for it to load, then send keystrokes to perform the resize operation. This involves using keyboard shortcuts to open the resize dialog (Ctrl+W), tabbing to the right field, entering your new size, and saving the image. Since this method is destructive (it saves over the original), I recommend copying the file first to create a backup.
I also provide support routines in my templates, such as SleepSeconds (to allow apps to catch up with automation), and I include links to my lessons covering SendKeys and other relevant techniques.
After sending the necessary key presses to resize and save the image in Paint, you can refresh the record in Access just like with the FFMPEG method. This ensures that the newly resized image displays as intended.
If you enjoy working with VBA and want to delve deeper into Microsoft Access programming, take a look at my developer lessons on the website. I cover a wide range of topics, and I am always looking for suggestions if you have questions or topics that I have not yet covered.
For further learning, try my free Access Level 1 course, which provides a solid foundation in Microsoft Access. For a speedier overview, I also have a concise Access for Beginners video. Level 1 is completely free, and Level 2 is available for just one dollar. Members at any paid level also get access to Level 2 for free.
If you want help with your specific Access questions, visit my TechHelp page and submit your inquiry there. Members will get priority for answers.
Finally, if you are interested in additional perks like access to extended cut videos (for Silver members and above), downloadable databases, my code vault, and priority in getting your questions answered, consider becoming a member at one of the available levels. All the details can be found on my website. Note that the highest levels of membership offer even more, such as company sponsorships and public recognition.
That wraps up this TechHelp tutorial. You can find a complete video tutorial with step-by-step instructions on everything discussed here on my website at the link below.
Live long and prosper, my friends.Topic List Resizing images for Access using FFMPEG Downloading and extracting FFMPEG for Windows Placing ffmpeg.exe in the images folder Writing VBA code to shell out to FFMPEG Building the FFMPEG command line to resize images Setting width with -vf scale and maintaining aspect ratio Using -q:v option to control JPEG output quality Copying and renaming image files with VBA Updating image display in Access after resizing Refreshing Access image controls after file changes Using Me.Recordset.Requery to refresh current record Alternative image resizing using Windows Paint Automating Paint resizing with VBA and SendKeys Step-by-step SendKeys sequence for Paint Making file backups before destructive saving Implementing SleepSec delays for automation timing Copying common VBA utility functions between projects Assigning resized images back to Access image controls
|