Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Images From OpenAI > < Fitness 31 | Fitness 32 >
Images From OpenAI
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   6 months ago

Create AI Art in Access Using the OpenAI DALL-E API


 S  M  L  XL  FS  |  Slo  Reg  Fast  2x  |  Bookmark Join Now

In this Microsoft Access tutorial I will show you how to use the OpenAI API to generate images from prompts directly within your Access database, including setting up the API key, configuring the correct models and options for images, handling user prompts and system messages, building the proper payload, troubleshooting requests, and working with the image URLs returned by OpenAI.

Members

In the extended cut, we will learn how to download the image generated by OpenAI from the URL to your local computer, store it in an images folder, and display it in your Microsoft Access database form. I will show you how to manage and view these images directly within your database.

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

Recommended Courses

Learn More

FREE Access Beginner Level 1
FREE Access Quick Start in 30 Minutes
Access Level 2 for just $1

Free Templates

TechHelp Free Templates
Blank Template
Contact Management
Order Entry & Invoicing
More Access Templates

Resources

Diamond Sponsors - Information on our Sponsors
Mailing List - Get emails when new videos released
Consulting - Need help with your database
Tip Jar - Your tips are graciously accepted
Merch Store - Get your swag here!

Questions?

Please feel free to post your questions or comments below or post them in the Forums.

KeywordsImages From OpenAI in Microsoft Access

TechHelp Access, OpenAI, ChatGPT, generate images, Access Database integration, API key setup, OpenAI API models, model 4.1, DALL-E3, prompt structure, image quality HD, image size limitations, response URL handling, bot table, system message integration, content moderation API, download image from URL, store images locally

 

 

 

Comments for Images From OpenAI
 
Age Subject From
6 monthsConversationsSandra Truax
6 monthsConversationJohn Davy
6 monthsExtended CutLars Schindler

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to Images From OpenAI
Get notifications when this page is updated
 
Intro In this video, I will show you how to connect your Microsoft Access database to the OpenAI API to generate images using your own prompts. We will go through updating your API key, choosing the best OpenAI model for image creation, copying and modifying the AskOpenAI VBA subroutine for generating pictures, setting image options like size, quality, and style, and handling prompt formatting, including escaping quotes and merging system messages. I will also cover parsing the response to get the image URL, building a simple picture bot, customizing style and quality options, triggering image generation with a form button, and troubleshooting common API issues.
Transcript Today, I am going to show you how to use OpenAI, which is the company behind ChatGPT, to generate images - whatever you can think of - using your Microsoft Access Database.

Before we get started, if you have not watched my OpenAI videos, it is a two-part series. Go watch these and build that database because that is the database I am going to start working with today. So go watch these and then come on back.

I downloaded the OpenAI video from my website. If you are a Gold Member, you can do that. If not, you will have to build it yourself following the videos.

The first thing I am going to do is go in the secret key module here and put in my API key, which goes right here. I will do my best not to flash that one on the screen like I have done before.

The next thing I am going to do - this video is about two years old and they have got a bunch of newer models available. I personally like the 4.1 model. Yes, version 5 is available. Actually, I am finding 4.1 easier to work with, so I am going to put 4.1 in there. It is faster. It does most of what I need. I found 5 has three models: Nano and Mini. You can find these by searching for OpenAI API models. 4.1 is, I think, the best one. It balances speed and is smart enough to do what you want it to do.

5 Nano is the smallest one. It does not work with anything. It is supposed to respond the fastest. Mini is not too bad. And version 5, which is supposed to think as much as it needs, is super slow. So I stopped using that one. But I like 4.1 still. It works the best for me.

This is just for your regular conversation and such, if you are using this database. Upgrade your model once in a while. Plus, the 4.1 supports a lot more tokens - basically, a lot more characters you can send back and forth. With the older versions, you have to chunk stuff up if you have really big training data.

In one of my upcoming videos, I am going to show you how to make your database remember the previous conversations so you can actually have a conversation with the API in your database. I do that a lot for customer service stuff, so we will get to that later.

Today we are going to focus just on getting pictures.

Now, I generally do not like copying data a lot, but we are going to make a copy of this AskOpenAI. We are just going to copy this whole thing, copy and paste it. Paste it down below here. Change it to AskOpenAIPicture or AskOpenAIImage or whatever you want to call it.

We are going to make two separate subs. There are some changes, some structural changes we have to make to the payload that we send. It is just easier to keep them separate.

Now we can still work with user content. Here is where you tell the AI what you want for your images. "Dogs playing poker" is what I did for the title slide. That is what we are going to use as a bad idea because you can change it up a little bit. You can say make this one look like a watercolor, make this one look like a chalk drawing, whatever.

Now for images, we have to change the URL that we are posting to. For this one, it is going to look like this. It is openai v1 images generations. So, like I said, a little bit different.

Model is the same. Now, for the send string, I am going to come right down here and I am going to paste this in because I have it on my clipboard. There it is. A little bit different. You are going to have to get the type right and be careful. Watch all of the spaces and the quotes. You can not CR it off the screen if you want to. Or if you are a Gold Member, you can just grab the database and copy and paste it right there.

Some different options in here: the model, DALL-E3, is the default model. The prompt is what the user content is. It is telling it basically what to make for the image. "n" is 1 here - that means you can tell it how many images to return, but we are just dealing with one at a time for now. You can say like make three of these.

Size: there are some different size options. Here they are right there. You have to use these. You cannot just type in any coordinates or dimensions you want. I am going to go with the smallest one for now.

Quality: there are two qualities. There is standard and HD. Standard is faster, smaller, and cheaper. HD is more detailed and higher cost. Yes, these do take tokens. It is not much; to generate a full HD image, I figured it out to be about 13 cents. It is not bad. But if you are going to be making lots and lots of these, the cost can add up.

We are going to stick with standard for now.

Then vivid or natural are the two options. Vivid is colorful, imaginative - you know, those AI generated pictures you see. Like when I make my Star Trek kind of pictures, I go with vivid. Natural, if you want it to be more photo-realistic. We are going to go with vivid for now.

One thing I forgot to do in the last video that I should do here: we should escape quotes in the user content because if the user types in user content with quotes in it, it is going to mess things up.

We have to be able to handle system messages, which are handled differently too. You do not actually send a separate system message. You have to integrate that in with the user content. I will show you that in a second.

So, right before we build the send string here, we are going to say userContent = Replace(userContent, actual double quote, backslash double quote), then close that string. So, in other words, if the user content includes an actual double quote, you have to go backslash double quote so it does not break the JSON string here.

Now, that user content - we no longer send a separate system message. So what we are going to do here is pretend our bot is the system message that goes in front of whatever actual text we send in the user content. So we are just going to say, if they specify a bot, get the system message and then say user content equals system message and then a dash or whatever and user content.

So if your system message says something like, "make this a watercolor painting with vivid colors, blah blah blah," and then the user content, they send in something like "I want a tree in a forest," those two just get merged together into one string. So here we do not even need to see that.

Now we are just sending user content, which we really do not even need as a separate variable, but we have it. So we open that up, we generate the send string, do our status. All this runs - that is all the same.

Now, just like before, we have to find between some stuff. It is going to be a URL, not content anymore. URL. What does that mean? Well, what OpenAI is going to do is it cannot send a picture to your Access database. It is not going to send a picture. So what it does is it generates a URL, a public-facing URL. That is a big, weird string of characters that is basically on the web. You can then go there and get that picture.

In fact, we have to change the end of it a little bit. It is going to be URL, then a colon, and then just another set of quotes like that. Let me double-check it. I had to copy and paste from my notes.

So you are looking, you are finding between in the response text: "quote URL quote colon quote", and then on the end of it is just another set of quotes. What is between there is going to be your response text. We do not need to delete trailing characters.

Now AskOpenAI - it is going to return... Well, this is going to be AskOpenAIPicture as the function. Is the response text. So it is going to return that URL.

Save it. Let's give it a Debug > Compile, cross our fingers. Same thing, same problem. AskOpenAIPicture, Debug > Compile again. One more time, catches all those. So we are good so far.

Let's make a bot next. Go in the bot table, and we will just come down here and say "Basic Picture Bot." Make a picture of the following like this. Then the user content will be whatever is after.

Here is where you could put whatever, because you might want to have like 10 different styles that you always work with and those options that I showed you before. Feel free to put this stuff in a table.

In fact, when I was playing around in my database, I made it so I can pick that stuff. In my database, I have HD as a checkbox, I have vivid and natural, and then I have these, which are all the different types of system messages that I want to send in there. I want it to be a chalkboard drawing or a crayon drawing or a digital painting. You can do Dungeons and Dragons style art. So it will tack that on to whatever the user content is.

Then there is the picture. In the extended cut for members, I will show you how to get that picture inside your database - well, not technically inside it, how to display it in your database. That will be in the extended cut.

For everyone else, we are going to get that URL now.

So we have our bot set. It is bot ID 7. Remember that.

Out here in design view, we have our bot combo right there. Let's make this a little bit more copy-paste, and we will say OpenAI Picture. Give it a good name. What did I call this one? Hello world, so the Hello World button. OK, GetPic button, just so Alex does not yell at us.

This will still be my text for my system message. So here, OpenAI Picture, right click, build event.

We are going to say:

Dim s as String
s = AskOpenAIPicture(MyText, 7)

That should return a URL.

I am going to see, does it status it? I think it statuses it when it gets definition. Does it? Let's see here.

We can status it here:

Status ResponseURL is response

So just so we can see it here too. Then we are going to return it. Once it is returned, we get to decide what we are going to do with it here.

Let's follow it.

FollowHyperlink s

That will open it up in your web browser.

Give me a beep.

Save it.

You can compile again.

Close it. Open it.

Let's do, how about again, dogs playing cards. That is my favorite one to do a sample of.

Where is it? Basic picture bot right there. Ready? Click. Oh, bad request. Oh, what happened?

In this case, this is where you do a little troubleshooting. I want to see exactly what is being sent to the AI. So let's go in here.

I want to see exactly what... Let's see here. Oh, I think I know what it is. No, that is not it. I was just saying user content send string. No, that is not it.

Here, I want to status the send string so I can take a peek at it and see what it looks like. It is usually something simple like a parameter is slightly off or whatever. But let's take a look at it.

All right, run it again. There it is right there.Now we can take a peek. Let's Shift-F2 zoom in.

All right, I did some troubleshooting off camera. It turns out I had to ask ChatGPT what the issue was. I sent it a copy of it. At first, it tried to tell me that my instructions were bad because they had a quote or a colon in here - make a picture of and then a colon. I simplified that, but it did not fix it.

Then it said it did not like the dash where I concatenated - where to put it in here. I got rid of the dash. That did not solve it. After analyzing my code, it said, oh, by the way, this model no longer supports anything but 1024 by 1024. So get rid of that.

So now you are basically stuck with just that one thing. After that, I clicked run and it did make an image and it looks all nice. There it is. It opened up my browser and there they are. Very cool. You can see here what that image URL looks like. That is a big, long one, the PNG file.

All right, let's try another one. I will try one about Kirk and Spock arguing. Now, I will say when I hit go here, I have had the image model complain. It would send back bad requests or whatever due to copyright issues, or it will make an image that is, well, it is okay. This one is not too bad. Pops up my browser. That is not too bad.

It has more guard rails on it than ChatGPT does. The ChatGPT engine can actually talk to the API AI in a way that it can get more out of it. It gives a lot more detail about exactly what Mr. Spock looks like, so you can get a closer looking Spock. The API is not going to give you that. It is just going to give you close enough images, but they are still good and you can still use them for a ton of different purposes.

Let's try one more. We are going to go for a barbarian like Conan wielding a sword being attacked by a dragon, castle in the background. Give me a picture. Let's see what it does.

See, now this one gave me a bad request and I will bet it is because of the "like Conan". Let's try "a barbarian wielding a sword." It could also be the punctuation. Let's try it again.

Yep. See, when in doubt, ask ChatGPT. It says, what is wrong with this prompt - a barbarian wielding a sword being attacked by a dragon, castle in the background? Weapon-related language, violence or combat, ambiguous phrasing. Sometimes it chokes on prompts that are not well-structured sentences.

So let's try this: a fantasy style barbarian standing in front of a dragon with a medieval castle in the background. Okay, let's try that. It is taking longer this time, so I think it is working. Yeah, there we go. There it is. Pretty good looking.

You have to be very careful with copyright and image violations and all that. You cannot make obviously not-safe-for-work stuff. You have to be careful with copyrights, violence, and when in doubt, just ask - like I just did - just ask GPT: What do you think is the problem with my prompt? It will tell you.

The content moderation API has a moderation endpoint you can call before sending a prompt to see if it will be flagged. I have not tried this yet. That is new. It is overkill for casual use, but if you want to prevalidate prompts - like if you are writing a book and you want to have your database generating images automatically, kind of like I do. I do not use AI for images. I pick screenshots out of my videos.

But here, avoid words like kill, attack, gun, sword, blood, all that stuff. I avoid too many of them because I do not want you flagging this video.

So there you go. That is how you get images. I get your database to generate images, which is what I promised up front.

Now, if you want to actually download those images to your PC, store them in an images folder, and display them in your database, you can go back and forth to the different images. All the images that I did here in my database while working on the fitness series, I did these: "right person sitting at a desk trying to build a Microsoft Access database." I have different styles. I did a 1950s retro poster, that kind of stuff, and a little penguin. My wife and I have a thing with penguins.

That is what we are going to do in today's extended cut. I am going to show you how to download that image from the URL they give you. Right - do not take the picture off the web, download it to your local computer because they do not keep it online very long. It is up there, I think, like three days or something they say it is active for, which, of course, this stuff changes all the time. We will download it off their website, store it on your local PC in your images folder, and then I will show you how to display that in your form. You can keep a little database with all your little images in it and it will be cool.

There you go. That is your TechHelp video for today. Hope you learned something. Live long and prosper, my friends. I will see you next time.

TOPICS:
Setting your OpenAI API key in the Access database
Selecting and updating OpenAI model versions
Copying and modifying the AskOpenAI VBA subroutine
Creating a new subroutine for image generation
Adjusting the API endpoint for image generation
Configuring the payload for image requests
Setting image model, prompt, and image count
Specifying allowed image sizes with OpenAI
Choosing image quality: standard versus HD
Selecting vivid or natural image style options
Escaping quotes in user-supplied prompts
Merging system message with user prompt
Parsing the OpenAI API response to extract image URL
Returning image URLs from a custom VBA function
Building a picture bot in the database
Customizing bots with predefined image styles
Adding options for style and quality in a table
Triggering image generation from a form button
Handling API errors and troubleshooting prompt issues
Testing and refining prompts for content moderation
Opening generated image URLs in a web browser
Interpreting and adapting to OpenAI API limitations
Tips for prompt wording to avoid moderation flags

COMMERCIAL:
In today's video, I will show you how to use your Microsoft Access database with OpenAI to generate images based on your ideas using the OpenAI API. We will walk through copying and modifying the AskOpenAI procedure to create images instead of just responding with text, updating API model settings, and handling things like prompt formatting, image options including size and quality, and parsing the URL returned by OpenAI to view your picture in a web browser. I will also discuss troubleshooting common issues with your prompts and tips about using style and quality settings. In today's Extended Cut, I will show you how to download the image to your PC, store it in an images folder, and then display it directly inside your database forms. You will find the complete video on my YouTube channel and on my website at the link shown. Live long and prosper my friends.
Quiz Q1. What is the main purpose of the tutorial in the video?
A. To explain how to generate text responses with OpenAI's older models
B. To show how to generate images using OpenAI and display them in a Microsoft Access database
C. To demonstrate setting up a SQL Server backend for Access
D. To compare OpenAI's pricing for different API keys

Q2. Why is it recommended to keep image generation and text conversation as separate subs or procedures in the Access database?
A. Because image generation and text conversation require different database file formats
B. Because each requires different payload structures and endpoints in the API call
C. Because only image generation supports tokens
D. Because only text conversation requires a secret key

Q3. When sending a prompt to the OpenAI image generation API, what is the primary thing that Access will receive in return?
A. The finished image in binary format
B. A public-facing URL where the generated image can be viewed or downloaded
C. A summary of the request for record-keeping
D. A set of related text responses

Q4. What is the role of the "prompt" in the API call to generate images?
A. It specifies the number of images to return
B. It defines the style or content of the image that should be generated
C. It controls the quality level of the output image
D. It decides which API model version to use

Q5. Which of the following is true about the available image "size" options in the OpenAI generation API?
A. You can specify any custom dimension in pixels
B. You must choose from specific predefined size options
C. The API will automatically resize images based on the user's screen size
D. The available sizes depend on your subscription level only

Q6. What do the image quality settings "standard" and "HD" affect?
A. The type of art generated by the API
B. The cost, level of detail, and processing time for the image
C. The type of prompt syntax allowed
D. The database schema required

Q7. Which of the following describes the difference between "vivid" and "natural" for image generation?
A. Vivid produces more text, while natural produces images
B. Vivid creates colorful, imaginative images; natural produces more photo-realistic results
C. Vivid is faster but lower quality than natural
D. Both produce the same type of images

Q8. Why is it important to escape double quotes in the user content when generating the send string in Access?
A. To encrypt the request data
B. To prevent the JSON string from breaking due to unescaped quotes
C. To make the prompt longer
D. To support multiple languages

Q9. How should system messages be handled differently in the image generation request, compared to earlier conversation APIs?
A. Send them in a separate field as before
B. Combine them with user content into a single prompt string
C. Ignore system messages entirely for images
D. Send them after the user content in the JSON

Q10. If you receive a "bad request" error from the API, what is a recommended first step?
A. Restart Microsoft Access
B. Review and status the send string to analyze what is being sent to the API
C. Switch to a different API key immediately
D. Pay for a higher plan

Q11. What are some common reasons that image prompts might be rejected by the OpenAI API's content moderation?
A. Including requests for abstract concepts only
B. Using ambiguous, violent, or copyrighted terms in prompts
C. Including technical code like SQL in the prompt
D. Referring to current news events

Q12. What does the moderation endpoint of the OpenAI API do?
A. Increases image generation speed
B. Prevalidates prompts to check for content violations before sending them to the image generator
C. Stores all images in your Access database automatically
D. Merges multiple user accounts

Q13. According to the video, what should you do if your prompt is not working and you get a bad request response?
A. Ignore the error and try again later
B. Ask ChatGPT for help analyzing and correcting the prompt
C. Reduce the size of the image
D. Use more explicit language in your prompt

Q14. After generating an image URL, what is the suggested way to view the image in your workflow?
A. Copy the URL to Notepad
B. Use the FollowHyperlink method in Access to open the URL in your browser
C. Import the image directly from the clipboard
D. Wait for OpenAI to email you the image

Q15. Why should you consider downloading generated images to your local PC after creation?
A. The image URLs are permanent and never expire
B. The images are only stored on OpenAI servers temporarily (such as three days)
C. It reduces your API usage cost
D. OpenAI requires local storage of all generated images

Answers: 1-B; 2-B; 3-B; 4-B; 5-B; 6-B; 7-B; 8-B; 9-B; 10-B; 11-B; 12-B; 13-B; 14-B; 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 will show you how to use OpenAI, the makers of ChatGPT, to generate images directly from your Microsoft Access database.

If you have not already watched my earlier OpenAI videos, which come as a two-part series, I recommend catching up on those first and building the corresponding database. That is the foundation I will be working with in this lesson.

I started by opening up that database and entering my API key into the secret key module. As always, be careful to keep your key secure.

Since the original OpenAI videos are about two years old, there are now many newer models available. Personally, I prefer using model 4.1 for most tasks these days. While version 5 is out, I found 4.1 to be quicker and reliable for my needs. Version 5 includes Nano and Mini models, which you can find by searching for OpenAI API models, but version 5 is slower, and the Nano model is extremely limited. For regular, conversational API usage in your database, I stick with 4.1, but make sure to update your model periodically as things keep evolving. Another advantage is that this version allows you to work with more tokens, meaning you're less likely to hit limits if you have large data sets to send or receive.

A future video will address how to have Access "remember" previous conversations in order to maintain a thread with the API, which I find useful for customer service applications. But today, our focus will be on generating images.

Although I am generally not in favor of duplicating code or data, in this case, we need to make a new subroutine by copying our existing AskOpenAI procedure. Paste it below and name the new routine something like AskOpenAIPicture or AskOpenAIImage, as you prefer. The need for separate subs comes down to the structural changes required in the payload sent to the API for image generation.

The basics remain similar; you specify what you want the AI to create as an image. For example, if you ask for "dogs playing poker," you can further specify styles, such as "watercolor" or "chalk drawing." With images, the main change is the API endpoint. You now post to the OpenAI v1 images generations endpoint which differs from the standard chat endpoint.

The new payload you send also requires certain options. The default image generation model is DALL-E 3. The prompt is created from your user input, which tells the API what kind of image you want. The parameter "n" controls the number of images, but I recommend starting with one. For image size, you must select from specific allowed sizes; entering custom dimensions won't work. For now, I use the smallest available size.

There are two quality options: standard and HD. Standard is faster, smaller, and cheaper, while HD provides greater detail but comes at a higher cost. Generating a full HD image costs about 13 cents, so if you plan to create many images, be mindful of the costs. For today's example, we will stick with standard quality.

You can also choose between 'vivid' and 'natural' styles. Vivid produces those colorful, imaginative AI-generated images you see around, while natural leans toward photorealistic results. I will use vivid for demonstration.

It is important to sanitize your user content before submitting it—especially escaping double quotes within the text, because these can break your JSON payload. Use a simple replace operation to ensure that embedded quotes are properly escaped.

For image generation, unlike conversational AI, you no longer submit a system message as a distinct field. Instead, append the system message to your user content, so both are merged into one prompt sent to the endpoint. For instance, if your system directive says to "make this a watercolor painting with vivid colors," and the user adds "I want a tree in a forest," these become concatenated so that all relevant instruction is combined.

Once the API responds, the result is not the image itself but a URL pointing to the generated image. The URL is a direct link to the image file, stored temporarily on OpenAI's servers. Your job is to extract that URL from the response, which involves looking for the right field in the returned JSON text.

To handle this, have your AskOpenAIPicture function return the URL. Save your changes, compile, and check for any errors as usual.

The next step is to configure a bot that can be used for image generation. In your bot table, add an entry for something like "Basic Picture Bot," with instructions such as "Make a picture of the following" followed by whatever the user enters. You could create additional bots for different styles or system messages, stored in tables for easy reuse. For instance, you can have options for standard or HD, vivid or natural, and style presets like chalkboard drawing or Dungeons and Dragons art.

For this demonstration, we'll use the bot ID we just set up. On your form, add a button, name it something meaningful, and set it to collect the user text and bot ID, then call your AskOpenAIPicture function. The result, which is the image URL, can then be opened in your web browser using the FollowHyperlink method. That will show you the generated picture.

If something goes wrong—like a bad request error—it is often due to a simple mistake in the parameter values or formatting in your payload. I recommend adding code to status or display the payload being sent, so you can double check when troubleshooting.

During my own debugging process, I encountered issues related to image size. The model now only supports 1024x1024 images, so you must use that size. Once I corrected this, image generation worked as expected, and the resulting images were viewable via the browser link.

You may also encounter errors when you use prompts that reference copyrighted content, violence, or ambiguous wording. For example, asking for "a barbarian wielding a sword" or referencing characters like "Conan" or scenes involving violence may result in bad requests or moderation rejections. The API's guardrails are more restrictive than what you might find chatting with ChatGPT itself. If you are unsure why a prompt is being rejected, you can even ask ChatGPT directly for help interpreting the error, or try rephrasing your prompt in a more neutral and descriptive way. Avoid words like "kill," "attack," "gun," "sword," and phrases about violence or blood.

OpenAI also offers a moderation endpoint to pre-screen prompts, which could be useful if you're automating large amounts of image generation and want to avoid moderation headaches.

At the end of the day, this method lets you use Access to generate images with AI—exactly as promised. If you want to go further—such as downloading the images, saving them to a local folder, and displaying them inside your Access form, that is exactly what I will cover in today's Extended Cut for members. I will show you how to download images from the provided URL, store them on your system, and organize them in your own image database. Keep in mind images hosted on OpenAI typically expire after about three days, so you will want to store copies locally if you intend to keep them.

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 Setting your OpenAI API key in the Access database
Selecting and updating OpenAI model versions
Copying and modifying the AskOpenAI VBA subroutine
Creating a new subroutine for image generation
Adjusting the API endpoint for image generation
Configuring the payload for image requests
Setting image model, prompt, and image count
Specifying allowed image sizes with OpenAI
Choosing image quality: standard versus HD
Selecting vivid or natural image style options
Escaping quotes in user-supplied prompts
Merging system message with user prompt
Parsing the OpenAI API response to extract image URL
Returning image URLs from a custom VBA function
Building a picture bot in the database
Customizing bots with predefined image styles
Adding options for style and quality in a table
Triggering image generation from a form button
Handling API errors and troubleshooting prompt issues
Testing and refining prompts for content moderation
Opening generated image URLs in a web browser
Interpreting and adapting to OpenAI API limitations
Tips for prompt wording to avoid moderation flags
Article If you want to use OpenAI's image generation capabilities directly in Microsoft Access, this tutorial will guide you through connecting Access to the OpenAI API (the company behind ChatGPT) for generating images on demand. We'll focus on building functions and forms that send prompts to OpenAI, receive generated images, and work with the results within your Access database. You'll need to be familiar with Access VBA and have an OpenAI API key before starting.

First, make sure you have a working Access database already set up to use the OpenAI API with text/chat functions. If you do not, you will need to create basic infrastructure for calling OpenAI APIs, handling API keys securely, and capturing responses—this is essential groundwork before adding image generation features.

Begin by storing your OpenAI API key securely. You'll usually want to place it in a dedicated VBA module. For example, in a standard module named ModSecrets, you might define:

Public Const OPENAI_API_KEY As String = "your-api-key-here"

Once your API infrastructure is in place, you'll need to update some elements to support image generation. OpenAI offers various models, but for images, you'll use their DALL-E model, which is available as DALL-E 3.

Text models like GPT-4.1 or 5 are not used for image creation, but this is worth knowing in case your workflow includes both chat and image functionality. DALL-E 3 is the model name you'll pass when making image requests. Note that for simple conversation or chat, you can choose models like gpt-4-1106-preview (4.1) for better balance of speed and capability, but image generation requires DALL-E specific endpoints.

To add image generation, start by making a copy of your existing VBA subroutine or function used for sending a text prompt to OpenAI. Save this as a new function—for example, AskOpenAIPicture. The reason for this duplication is that the payload (the JSON you send to the API) and the endpoint (the URL you post to) are both different from those used for chat functions.

For image requests, the correct URL is:
https://api.openai.com/v1/images/generations

The request you send must contain several elements. Here is an example of a correctly formatted JSON payload for image generation:

{
"model": "dall-e-3",
"prompt": "<your prompt here>",
"n": 1,
"size": "1024x1024",
"quality": "standard",
"style": "vivid"
}

The "prompt" field is your descriptive instruction for the image. "n" is the number of images to generate—start with 1 for simplicity. "size" must be one of OpenAI's predefined sizes. As of now, DALL-E 3 supports only "1024x1024". "quality" can be "standard" or "hd" (HD images are higher quality and cost more). "style" can be "vivid" (for colorful, imaginative pictures) or "natural" (for photorealistic images).

When constructing your JSON, be sure to escape any double quotes within the prompt. You can do this in VBA like so:

userContent = Replace(userContent, """", "\\""")

This ensures any double quotes in user input are properly escaped, avoiding invalid JSON errors.

Since DALL-E's API expects any system message or context to be included in the prompt itself, you can concatenate predefined instructions/styles with the user's request when building your message. For example, if you want all images to look like watercolor paintings, you could prepend "Make this in the style of a watercolor painting: " to whatever the user enters.

Here is sample VBA code to send a prompt to OpenAI's DALL-E 3 and return the image URL. This code assumes you have a function (like HttpPost) to send an HTTP POST request and return the response. You will need to parse the returned JSON for the "url" field.

Function AskOpenAIPicture(prompt As String) As String
Dim url As String
Dim apiKey As String
Dim sendString As String
Dim response As String
Dim imageURL As String

url = "https://api.openai.com/v1/images/generations"
apiKey = OPENAI_API_KEY

' Escape double quotes in prompt
prompt = Replace(prompt, """", "\\""")

sendString = "{""model"":""dall-e-3"",""prompt"":""" & prompt & """,""n"":1,""size"":""1024x1024"",""quality"":""standard"",""style"":""vivid""}"

response = HttpPost(url, sendString, apiKey)

' Extract the 'url' field from the JSON response
Dim startPos As Integer
Dim endPos As Integer
startPos = InStr(response, "url"":""") + 6
endPos = InStr(startPos, response, """")
imageURL = Mid(response, startPos, endPos - startPos)

AskOpenAIPicture = imageURL
End Function

This function constructs your request, sends it off, and extracts the resulting image URL from OpenAI's response.

To display or use this image, you can open it in a web browser using Access VBA:

FollowHyperlink imageURL

This will show the generated image in your default browser.

If you want to make this user-friendly, you can add a form with a button, a text box for the prompt, and perhaps a dropdown or checkboxes for styles or qualities. Create a button that, when clicked, gets the text from the prompt box, calls AskOpenAIPicture, and displays the resulting image.

Be aware that OpenAI will not send the actual image data to your Access database. Instead, it returns a temporary public URL to download the image from. These URLs typically remain valid for a few days, but for longer-term use or offline access, you should download the image and store it on your computer or in your database.

If you want to fetch and download the image, you can use standard VB or VBA methods for HTTP file download, then display the image on your forms or reports using an Image control linked to the downloaded file.

Also note, OpenAI's content moderation can occasionally reject prompts based on content policy—phrases involving violence, weapons, or copyrighted characters may not work, or could return errors. If you get repeated "bad request" errors and your code is otherwise correct, try simplifying or rephrasing your prompt, avoiding ambiguous or policy-violating terms.

For robust routine use, consider calling OpenAI's Moderation endpoint before sending any prompt for image generation, to check for possible policy violations.

Finally, as you build out your application, you can store favorite styles, predefined prompts, quality settings, or even bot personas in a table for user selection. This way, you can quickly generate a variety of image types—such as digital paintings, chalk drawings, or retro art—by combining stored settings with the user's request in your form.

With this setup, your Access database can create images programmatically through OpenAI's DALL-E, making it possible to enhance records, automate creative tasks, or build dynamic content as you see fit. Just keep an eye on token cost, moderation limits, and do not rely on permanent hosting of your images without downloading them to your own computer.

That is how you can get started with generating AI images from Microsoft Access using the OpenAI API. With careful prompt construction and some simple VBA, you can bring dynamic, creative image functionality into your Access projects.
 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/16/2026 1:18:01 AM. PLT: 1s
Keywords: TechHelp Access, OpenAI, ChatGPT, generate images, Access Database integration, API key setup, OpenAI API models, model 4.1, DALL-E3, prompt structure, image quality HD, image size limitations, response URL handling, bot table, system message integration,  PermaLink  Images From OpenAI in Microsoft Access