Images From Web
By Richard Rost
3 years ago
Display Images from the Web in Microsoft Access
In this Microsoft Access tutorial, I will show you how to display images from the web in your forms and reports using the image control and not the Web Browser control. This technique is superior because it will work with continuous forms.
Fernando from Tuscon, Arizona (Platinum Member) asks: I download a monthly spreadsheet from my parts supplier that has updated pricing and such. One of the fields they give me is a URL to the product's picture on their website. Is there a way I can display that picture in my Access forms and reports?
Members
Members will learn how to download each image from the web and save it in an images folder based on the customer's ID. We will then learn how to download the file to your browser cache without actually having to save it in a folder. This is good if you don't care to keep a local copy of each file. We will also see how to use both of these types of files in a continuous form to display multiple images at the same time.
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!
Pre-Requisites
Links
Recommended Courses
Source Code
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, URLDownloadToFile, URLDownloadToCacheFile, show pictures from web, show images from web, Show pictures directly from URLs, Display Web Images, Show Load pictures from URL, download image, download file
Intro In this video, I will show you how to display images from the web in your Microsoft Access Forms and Reports using the Image Control. We will talk about how to use VBA to download an image from a URL provided in your data, save it to your local computer, and then show it in your forms. I will walk you through copying the source code needed, setting up the Image Control, and linking it to your data. We'll also discuss the benefits of the Image Control versus the Web Browser Control when displaying images from the web in Microsoft Access.Transcript Welcome to another TechHelp video brought to you by AccessLearningZone.com. I am your instructor, Richard Rost.
In today's video, I'm going to show you how to display images from the web in your Microsoft Access Forms and Reports using the Image Control.
Today's question comes from Fernando in Tucson, Arizona, one of my platinum members. Fernando says, I download a monthly spreadsheet from my parts supplier that is updated pricing and such. One of the fields they give me is a URL to the product's picture on their website. Is there a way I can display that picture in my Access Forms and Reports?
Well yes, Fernando. In fact, a little while ago, I did a video called Online Images. In this video, I show you how to use the Web Browser control to display pretty much anything you want, any web page or a picture online using the Web Browser control.
Well in today's video, I'm going to show you how to do it using the Image Control, which has some major benefits over using the Web Browser. We'll talk about those benefits a little later, but let me first show you how this works.
Now I do have this marked as a developer level TechHelp. So you will need a little bit of VBA programming. If you've never done any VBA programming before, don't be scared. Go watch this video; there's a link to it down below, you can click on it. It's about 20 minutes long, teaches you everything you have to know to get started with VBA.
Also, if you haven't watched my regular images video, go watch this first. Very important. In this video, I show you how to take images from your hard drive and display those in your Access Forms and Reports.
Well, in today's video, what we're essentially going to do is go out to the web, grab that file, save it, download it to a file on our local drive, and then display that for the customer's picture, or the product's picture, or whatever picture you want to use.
Here I am in my TechHelp free template. This is a free download; you can grab a copy from my website if you want to. Before we get started today, we're going to need to copy some source code off my website as well. I'm going to make it free for everybody; you can grab a copy of it. This isn't something you're going to want to have to retype. I don't want to have to retype it. So just copy it off my website.
You'll find a link in the description down below the video. It's called URL download to file. You're going to click right here on the copy button. That'll copy it to your clipboard. We're going to come back to our database and create a module.
Here we are in the code editor; just paste in that code. There you go.
Now this is designed for 64-bit Access. If you don't have 64, you've got 32-bit; just delete that word, point your save right there.
Now this guy up here, this big, huge thing that starts off with public declare... This is a function straight from Microsoft called URL download to file. Essentially, you specify a URL, which is a fully formed web page address, and then it will download that file from the web to your local PC.
I wrote a little helper function right here called my download, where we're going to specify that URL and then save it to whatever file you want on your local hard drive. I'm going to put mine in gmydrivetest.jpeg.
In fact, I'm going to change mine just slightly. I was playing around earlier. I made an images folder and I put Captain Kirk in there. So I'm going to delete Captain Kirk. We're going to change my folder to images.
So come back here in the source code. We're going to make this my drive images and then test.jpeg. Honestly, it doesn't matter what kind of file you're downloading. It could be a jpeg, a gif, a png, a bitmap. It doesn't matter. Access won't care. The file extension really doesn't matter. But that's OK. Just ignore that for now.
Make this a valid folder on your computer, where you can save a file: your desktop or wherever you want to put it. What we're going to do is we're going to call the my download function, send it the URL. That's going to be any picture online you want to grab. There's the local file.
Now, result equals URL download file. What that's going to do is this: it's going to go out to the web, find that URL (whatever picture you specify), and save it in the local file that you specify. The result is going to be a zero if it's successful, in which case my download, the name of the function, will return that local file name. Otherwise, if it's not successful, if it's not able to download that file, it'll return an empty string, in which case nothing will happen. All you have to know how to do is simply call my download, and I'll tell you how to do that in just a second.
Save this. Let's call this download mod. Now let's go back over here. Let's go to our customer form.
Now, this is going to work very similarly to what we did with our regular images. In fact, I'm going to get rid of all of this stuff here. We don't need it for this example.
Let's insert an image control. Don't use this. So remember from the other video, use this guy: Image right out of the toolbox. Grab it right there. Cancel this. There's our blank image control.
Now I'm going to cheat. I don't want to have to add another field. I'm just going to use the email address field as the address for the picture.
I'm going to change it over here. Image. We're going to cheat and say the email field has the image file name.
So we're all on the same page. Let's open this guy up. Give me its properties. I don't like image 30. Let's call that my image.
Now for the control source, we're going to use that my download function that we just specified a minute ago: =mydownload(
What's the URL? What's the field that's going to have the picture for this guy? Well, we're cheating - email. Normally, you put in there like picture URL or whatever it's going to be.
Got it? Let's save it. Control S. Let's close this all down.
Open it up.
Now right at that second, Access is trying to find the URL in the chrono Gmail account. That doesn't exist. Let's put a picture URL in here.
Now, I know from previous classes I've got some image files on my website in the images folder. There's Kirk. I'm just going to copy that, come in here, and paste that in my image field for that customer.
Look at that. See what happened? The my download function was called, and that picture was grabbed off my website, saved on the hard drive with the URL download file function, and now it's being displayed right here. If I go check on my hard drive, look at that. There's test.jpeg. That's Captain Kirk.
Let's do another one. I put Captain Kirk in for me. That's OK. We'll skip him. I know I've got one for Picard too. Let me go to my website here, and I'm pretty sure he's right there. There he is: Picard.jpeg.
Let's copy that, come back over here, paste it in the image field, and tab. There he is. If I check my folder, look at that. It updated. Same file, but it updated.
Can you save each of these individually based on the customer ID? Yes, sure. You could.
There are some other benefits and some other reasons why you want to use the image control instead of the web browser control. I mentioned at the top of the video that I would tell you what that is.
The major benefit is that the web browser control cannot be used in a continuous form. So if you want to display multiple images, either in a form or a report, you've got to use the image control, not the web browser control.
In the extended cut for the members, I'm going to show you how to download each of these and save them based on that customer ID in an images folder. Then I'll show you how to display them in a continuous form. I'll show you another trick where we can do something very similar, but we don't have to save the file. We can just use our browser's image cache. That's really pretty cool.
That's all covered in the extended cut for the members. Silver members and up get access to all of the extended cut videos. Gold members can download these databases.
I hope that shows you how to download an image from the website and display it in your Access Forms and Reports. Reports work the same way. Just put the same control in, put the same function in it, it'll work just fine.
If you have any questions or comments, feel free to post them down below.
I hope you enjoyed, hope you learned something, and I'll see you next time.Quiz Q1. What is the main purpose of the video? A. To teach how to display images from the web in Access Forms and Reports using the Image Control B. To explain how to secure your Access database C. To create a report in Access using VBA D. To generate barcodes in Access
Q2. Which function is used to download an image file from a URL in the provided VBA code? A. GetImageFromWeb B. URLDownloadToFile C. AccessDownloadImage D. WebImageFetch
Q3. What is a key benefit of using the Image Control instead of the Web Browser Control in Access? A. Image Control supports continuous forms, unlike Web Browser Control B. Web Browser Control consumes less memory C. Image Control requires no VBA code D. Web Browser Control renders images faster
Q4. In the example, which field did Richard use to simulate the image URL for demonstration purposes? A. CustomerName B. Address C. Email D. Phone
Q5. What should you do with the VBA source code provided by Richard on his website? A. Retype it manually in your database B. Import it using the External Data tool C. Copy it from his website and paste into a new module in your database D. Download an Access add-in to install it
Q6. What is returned from the mydownload function if the image download fails? A. The URL of the image B. An empty string C. The error code D. The local file name
Q7. Where should the downloaded image be saved, according to Richard's demonstration? A. Any valid folder on your computer B. Only the C drive C. The Windows system folder D. The Access installation directory
Q8. What is the recommended way to insert an image control in the Access form, according to the video? A. Using the Image tool from the toolbox B. Using the Attachment field C. Dragging a file from Windows Explorer D. Using the Insert menu
Q9. Why is it important to ensure the file path in the VBA code is valid? A. Because Access will automatically create folders if they do not exist B. Because the code will fail if the folder does not exist C. The file path can be any random string D. It has no effect on the outcome
Q10. What should you do if you are new to VBA and want to follow along with the tutorial? A. Skip the video B. Watch Richard's 20-minute introductory VBA video C. Install a third-party VBA editor D. Buy a separate VBA training course
Answers: 1-A; 2-B; 3-A; 4-C; 5-C; 6-B; 7-A; 8-A; 9-B; 10-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 video from Access Learning Zone demonstrates how to display images from the web in Microsoft Access forms and reports using the Image Control.
A question came in about this topic. One of my viewers mentioned that he regularly downloads a spreadsheet from his parts supplier which includes a field with a URL to the product's image on the supplier's website. He wanted to know if there is a way to display that picture directly in his Access forms and reports.
The answer is yes, and there are a couple of different methods for accomplishing this. Not too long ago, I recorded a video where I explained how to use the Web Browser control to display online images or even entire web pages inside Access. However, today I want to show you how to use the Image Control, which offers several advantages over the Web Browser approach. I will explain those benefits as we go along.
This is a developer-level topic, so some VBA programming is required. If you are new to VBA, don't let that intimidate you. I have a beginner-friendly introduction to VBA video, roughly 20 minutes long, that will bring you up to speed. You can find the link to that video on my website.
Before you proceed, I also recommend watching my standard images video, which covers how to display pictures from your hard drive in Access forms and reports. It is important to understand that fundamental technique since today's lesson builds on those concepts by extending them to web images.
The process involves downloading an image from a URL, saving it as a file on your local system, and then pointing the Image Control in Access to that file so it can be displayed. This way, you can present a customer or product photo—or any type of image—sourced from the web right inside your database.
You can use my TechHelp free template to follow along, which is available on my website. You will also need to copy some VBA source code, also provided on my site at no cost, because you probably don't want to type it all out yourself. Look for the URL download to file code and copy it to your clipboard.
Once you bring this code into your Access database, paste it into a new module. The code is set up for 64-bit Access, but if you are using 32-bit Access, a very minor change is needed: just delete the 'PtrSafe' keyword.
The main piece of the code is a function called URL download to file, which is provided by Microsoft. It allows you to specify any online file's URL and save that file to your computer. I've added a simple wrapper function called my download, which lets you supply the URL and the location where you'd like the image saved. Adjust the folder path to point to a valid location on your computer such as your desktop or a designated images folder.
After you save the module, you are ready to set up your form. The process is nearly identical to how you would show locally stored images, so the structure will be familiar if you have watched my previous video on local images.
Insert an image control from the toolbox onto your form. Do not use the legacy OLE control, just use the Image Control. Next, choose a field in your table or form that will store the URL. For convenience, I used the existing email field as a placeholder for the image URL, but in a real project, you should use a dedicated field for image links.
Rename your image control to something memorable, such as my image. Set the control source property to call your my download function and pass it the appropriate field containing the URL. This way, when you open a record where the image field contains a valid URL, the function grabs the image from the web, saves it to your specified local folder, and then the Image Control loads the saved file.
You can easily test this by copying an actual image URL and pasting it into the designated field. Then, when you navigate to the record, the function will execute, download the picture, and display it in your form. If you check the specified folder on your hard drive, you'll see that the image file appears there.
If you would like to save multiple images—say, one for each customer—you can tailor the code so each saved file name includes a unique identifier such as the customer ID.
There are important reasons for preferring the Image Control over the Web Browser control. Most significantly, the Web Browser control is not compatible with continuous forms; this limitation makes it unsuitable for displaying multiple images at once, such as in multi-record forms or reports. The Image Control, in contrast, works fine in those views, making it the better choice for these situations.
For those interested in a more advanced approach, the Extended Cut for members covers how to save images for each customer in a dedicated images folder, how to show images in continuous forms, and an alternative method that utilizes the browser's image cache, which allows you to display images without permanently saving them to disk.
To recap, now you know how to download images from the web and display them in your Access forms and reports using the Image Control and a simple helper function. The same technique works in reports—just add an image control, call the function, and you're ready to go.
If you have any questions or want to discuss further, please leave me a comment. 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 Displaying web images in Access forms using Image Control Downloading images from a URL to a local file with VBA Creating and pasting VBA modules in Microsoft Access Modifying folder paths in VBA code for image storage Setting up the Image Control in Access forms Binding the Image Control to a downloaded file Using a form field to store the image URL Testing image download and display functionality Key differences between Image Control and Web Browser Control in Access Using Image Control in continuous forms and reports Updating images by changing the URL in a form field
|