Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Database Title & Icon    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Change Icon
John Haubjerg 
     
2 years ago
Hi

Is it possible to save icon for access in the database instead of path?

Thanks
John

Alex Hedley  @Reply  
            
2 years ago
Is this so you don't have to distribute an .accdb and an image file?

You might be able to encode it as a string and set it via VBA instead.
Kevin Yip  @Reply  
     
2 years ago
You need external tools (and skills to use those tools) to "embed" icons inside .exe files that you didn't create yourself (Microsoft created msaccess.exe, not you).

Another way is to create the .exe yourself, such as with Visual Studio, which lets you set the application icon on the property sheet.
Richard Rost  @Reply  
          
2 years ago
While I usually am against storing images inside the database, you might be able to store a BMP file in an OLE Object and then extract it once the database runs for the first time, and then use that as the icon. This is a "might be" though as I've never tried it.
Richard Rost  @Reply  
          
2 years ago
Here's what GPT has to say:

Yes, it's possible to use an image in a Microsoft Access database as the database icon, but it requires a workaround since Access itself doesn't have a direct setting to dynamically set the database icon at runtime.

Here's how you can do it:

Option 1: Set a Custom Icon for the Database Manually
1. Use the Access Options: You can set a custom icon for your database through the Access Options:
   - Click on File > Options > Current Database.
   - Under Application Icon, click Browse to select the `.ico` file you want to use.
   - Check Use as Form and Report Icon if you want the icon to appear on all forms and reports.
   - This will require the image to be converted to an `.ico` file format beforehand.

Option 2: Extract and Use an Image Programmatically at Startup
If you want to dynamically use an image as the icon when the database starts, you can extract an image stored in the database and save it as an icon file (`.ico`) when the database opens. Here's a general approach to achieve this:

1. Store the Image in an OLE or Attachment Field:
   - Create a table that contains the image, either as an OLE Object or as an Attachment.

2. Extract the Image on Startup:
   - Use VBA to extract the image from the table and save it as an `.ico` file in a temporary directory.
   - The VBA code would look something like this:

Code   Private Sub Form_Load()
       Dim rs As DAO.Recordset
       Dim imgPath As String
       Dim imgData As Variant

       ' Adjust table and field names accordingly
       Set rs = CurrentDb.OpenRecordset("SELECT [ImageField] FROM [IconTable] WHERE [ID] = 1")
      
       If Not rs.EOF Then
           imgData = rs!ImageField
           imgPath = Environ("Temp") & "\database_icon.ico"
           SaveBinaryToFile imgData, imgPath
          
           ' Set the application icon to the extracted image
           Application.SetOption "AppIcon", imgPath
       End If
      
       rs.Close
       Set rs = Nothing
   End Sub

   Private Sub SaveBinaryToFile(binData As Variant, filePath As String)
       Dim fileNum As Integer
       fileNum = FreeFile
       Open filePath For Binary Access Write As #fileNum
       Put #fileNum, , binData
       Close #fileNum
   End Sub


3. Set the Icon Property:
   - The code above sets the application icon dynamically using the `Application.SetOption` method.

Note: The `.ico` file format must be used for Access to accept it as an icon, so you may need to handle converting the image if it is in a different format (like `.bmp` or `.jpg`).

This approach provides flexibility, allowing you to change the icon based on conditions in your database or other preferences, but it does require some VBA scripting to implement.
Richard Rost  @Reply  
          
2 years ago
Again, I have NOT tested this. Let me know if it works. Might make a cool video.
John Haubjerg OP  @Reply  
     
2 years ago

John Haubjerg OP  @Reply  
     
2 years ago
Hi again

I got runtime error '13'
Type mismatch

I made a table with icon.ico in it. I used the code but get this error when I run it. I don't know what's causing it, and it's something that can be fixed

//John
Kevin Robertson  @Reply  
          
2 years ago
I also asked ChatGPT based on your image (I haven't tested this):

The "Type mismatch" error (Runtime error 13) in VBA usually occurs when there is an attempt to assign or manipulate a variable with a type that is incompatible with the operation being performed. In your case, the error might be caused by the binData variable's type, which is declared as Variant, but the Put statement might expect a different data type when writing to a binary file.

To fix this, ensure that binData contains valid binary data that can be written to a file. One potential issue could be that binData is being treated as a recordset field value (potentially Null or Empty), which causes the mismatch.

Here are a few things you can check or modify:

1. Verify that binData is not Null or empty:
Add a check to make sure binData contains actual binary data before calling SaveBinaryToFile.

DetailsIf Not IsNull(imgData) Then
    SaveBinaryToFile imgData, imgPath
Else
    MsgBox "No binary data found in the field."
End If


2. Explicitly cast binData:
If binData is coming from a recordset field, it might need to be explicitly cast to a type that the Put statement can work with, such as Byte array. You can try casting it like this:

DetailsDim byteData() As Byte
byteData = imgData
SaveBinaryToFile byteData, imgPath


Then modify the SaveBinaryToFile procedure to accept a Byte array:

DetailsPrivate Sub SaveBinaryToFile(binData() As Byte, filePath As String)
    Dim fileNum As Integer
    fileNum = FreeFile
    Open filePath For Binary Access Write As #fileNum
    Put #fileNum, , binData
    Close #fileNum
End Sub

John Haubjerg OP  @Reply  
     
2 years ago

John Haubjerg OP  @Reply  
     
2 years ago
now I get this error in imgData -

SaveBinaryToFile imgData, imgPath
John Haubjerg OP  @Reply  
     
2 years ago
Hi again again
This runs with no errors, but nothing happen. No icon.ico in the tempfolder or in Access.

How do I write in the foldable Detals like you guys do


      
John Haubjerg OP  @Reply  
     
2 years ago

Alex Hedley  @Reply  
            
2 years ago
What is imgData and where is it?
John Haubjerg OP  @Reply  
     
2 years ago
It's a ico file stored in the table IconTable
Alex Hedley  @Reply  
            
2 years ago
Your imgData will always be null because you haven't set it to anything yet

If Not IsNull(imgData) Then

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Database Title & Icon.
 

Next Unseen

 
New Feature: Comment Live View
 
 

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: 6/22/2026 9:22:20 PM. PLT: 1s