Cannot create image object

apeters

Registered User.
Local time
Today, 21:57
Joined
Nov 21, 2008
Messages
24
I'm trying to create an image object programmatically, but I get "ActiveX component can't create object". Here's the code:

Code:
Dim objImage As Access.image
Set objImage = New Access.image

Can anyone tell me why this is happening, please? I'm using Access 2007.
 
You need to explain exactly what you are trying to acheive.

Simon
 
I'm trying to populate a table with the file paths and dimensions of images (jpg, gif & png) found in a specific (Windows) folder.

I'm using a Scripting.FileSystemObject to obtain the list of file paths, but I also need to get the dimensions of each image.

I was hoping to programmatically create an access.image object, set its 'picture' property to the desired file path, and hence obtain the image dimensions from its 'imageWidth' and 'imageHeight' properties. Unfortunately, I seem to be stuck at the first hurdle, since I can't create the image object!
 
Many thanks to Spikepl for the useful link. I'm trying to get the sample code working in MS Access 2007, but am getting an error message "object variable or With block variable not set".

I've created references to Microsoft Internet Controls (SHDocVw) and Microsoft Shell Controls and Automation (Shell32), as explained on MSDN, and have created the following function:

Code:
Private Function getImageDims(strFolderPath As String, strFilename As String) As String

    Dim objShell As Object
    Dim objFolder As Object
    Dim objFolderItem As Object
    
    strFolderPath = "c:\temp" 'TEST
    strFilename = "Invoice.bmp" 'TEST
        
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.NameSpace(strFolderPath)
    Set objFolderItem = objFolder.ParseName(strFilename)
    getImageDims = objFolder.GetDetailsOf(objFolderItem, 26)

End Function

The error occurs at the following line:
Code:
Set objFolderItem = objFolder.ParseName(strFilename)

This is because objFolder is Nothing at that point! What I don't understand is why it is Nothing. I know that strFolderPath exists on my hard disk. Any ideas?

André
 
Spikepl, many thanks once again for your help. Using double-brackets got rid of the error message.

It took a while to get the whole thing working because the vast majority of references on the web suggest that the second argument of getDetailsOf should be 26, whereas on my system it is 31 (found by trial & error). I don't know whether this is because I'm using Windows 7 or if there is some other reason. There is very little documentation on the web about it.

Here's the final, working code for MS Access 2007 on Windows 7, for anyone that wants it:

Code:
Private Function getImageDims(strFolderPath As String, strFilename As String) As String

    Dim objShell As Shell32.Shell
    Dim objFolder As Shell32.Folder
    Dim objFolderItem As Shell32.FolderItem
 
    Set objShell = New Shell32.Shell
    Set objFolder = objShell.NameSpace((strFolderPath))
    Set objFolderItem = objFolder.ParseName(strFilename)
    getImageDims = objFolder.GetDetailsOf(objFolderItem, 31)
    
    Set objShell = Nothing
    Set objFolder = Nothing
    Set objFolderItem = Nothing

End Function
 
Thx for posting back. I run XP and 26 works for me.
 

Users who are viewing this thread

Back
Top Bottom