Forum Discussion
Problem with Shell32 object class in MS Access
shell32.ShelfolderItem is no longer recognizing variables.
I have several MS Access databases that interrogate the file system on Windows 10.PCs. They look for dated material that needs to be purged, categorized, or backed up. I have been using shell32 for several years for this purpose. Now, the ShelFolderItem object no longer recognizes variables as arguments.
I haven't run the routines for a while. So I can't tell just when the issue might have started. My MO365 build is "Microsoft® Access® for Microsoft 365 MSO (Version 2201 Build 16.0.14827.20158) 64-bit" My latest system update is "February 8, 2022—KB5010342 (OS Builds 19042.1526, 19043.1526, and 19044.1526)"
Below is a sample subroutine and the subsequent output that demonstrates my problem. I hope someone can offer an explanation and suggestion to fix this.
Edit 2/11/2022 11:12 EST
I'm guessing that it might have something to do with the latest version of MO365 I have is running as a 64bit app while the shell32 object might be limited to 32bit. Is that true? If so, how do I make it safe for a 64bit environment?
Sub sample_of_error()
Dim Shel As shell32.Shell, ShelFolder As Object, ShelObject As ShellFolderItem, iInt As Integer, iStr As String
On Error GoTo errHandler
'Set Shell namespace and folder
Set Shel = New shell32.Shell
Set ShelFolder = Shel.NameSpace("C:\Program Files (x86)\Windows Media Player")
Debug.Print "Literal value of 1 used as the argument for the index parameter to set ShelObject."
Debug.Print "Call to ShelObject.name results in:"
Set ShelObject = ShelFolder.Items.Item(1) 'Set Shellobject to the first item in the folder using the literal value of 1
Debug.Print ShelObject.Name
Debug.Print vbCrLf
Debug.Print "Variable iInt with value = 1 used as argument for the index parameter to set ShelObject."
Debug.Print "Call to ShelObject.name results in:"
iInt = 1
Set ShelObject = ShelFolder.Items.Item(iInt) 'Set Shellobject to the first item in the folder using a variable with value of 1
Debug.Print ShelObject.Name
GoTo Done
errHandler:
Debug.Print "ERROR: " & Err.Number
Debug.Print "ERROR: " & Err.Description
Done:
Set ShelObject = Nothing
Set ShelFolder = Nothing
Set Shel = Nothing
End Sub
Debug Output:
Literal value of 1 used as the argument for the index parameter to set ShelObject.
Call to ShelObject.name results in:
Icons
Variable 'iInt' with value = 1 used as argument for the index parameter to set ShelObject.
Call to ShelObject.name results in:
ERROR: 445
ERROR: Object doesn't support this action
- this will work:
Dim Shel As Shell32.Shell, ShelFolder As Shell32.Folder, ShelObject As Shell32.FolderItem, iInt As Integer, iStr As String
4 Replies
- arnel_gpIron Contributorchange the declaration iInt (from Integer to Variant):
iInt As Variant- RBStewartCopper Contributor
Thank you. That may be better than the one I stumbled upon. It will depend on the incidence of casting issues as the functions and modules pass the item index variable into and through one another.
I discovered another solution that affects only the Set ShelObject statement leaving all variables as originally declared. I can set the ShellFolderItem object simply by setting it from the Shel.Namespace object directly. Shel.Namespace continues to accept Integer, Long, String and Varaint data types as inputs into the item index parameter, whereas the folder object (declared as type object) now only accepts variant as you suggest. In practice I would like to preserve the object hierachy Namespace > Folder > FolderItem in the code. I'll take a close look at both alternatives. Here is what I found.A sub having...
Dim Shel As shell32.Shell, ShelFolder As Object, ShelObject As ShellFolderItem
Dim iInt As Integer
and comparing the following blocks of code to set the FolderItemObject
this statement works...Set ShelObject = Shel.NameSpace("C:\Program Files (x86)\Windows Media Player").Items.Item(iInt)
while this fails...Set ShelFolder = Shel.NameSpace("C:\Program Files (x86)\Windows Media Player")
ShelObject = ShelFolder.Items.Item(iInt)- arnel_gpIron Contributorthis will work:
Dim Shel As Shell32.Shell, ShelFolder As Shell32.Folder, ShelObject As Shell32.FolderItem, iInt As Integer, iStr As String