Hello,
I have a function designed to update a Dictionary object. All works well, but now I want to make the function more generic by having it instantiate a new dictionary object by passing a name. The motive is to use the function across different dictionaries. The problem is that the vba compiler won't compile the dictionary Name as it complains of a type mismatch.
In brief the function and code looks something like this: pass the name of the dictionary object I want to access, pass the operation I want to do, and an optional value.
Public Function GenericDictionary(dictName As String, dictMethod As String, optional dictValue as String ) As DictRtn
Select Case dictMethod
Case "instantiateDict"
Static dictName as Scripting.Dictionary
Set collectionName = New Scripting.Dictionary
……
Update DictRtn with something here….
….
End Select
return something here...
End Function
The complier won't accept the DictName in the Static statement. I believe I can understand why the type error is generated, but I need to insert the actual name that I pass with dictName and then have it compile to instantiate. I've attempted to do a DoCmd.rename, but the complier complains of undefined variables (ie DoCmd.rename dictName, Scripting.Dictionary, dictDefaultName) where dictDefaultName is something that I can predefine as a Scripting.Dictionary object.
Any suggestions or hints on how to get the compiler to type cast a string to a Scripting.Dictionary object? Suggestions on how to properly do the DoCmd Statement?
Thanks for any suggestions or help.
David
I have a function designed to update a Dictionary object. All works well, but now I want to make the function more generic by having it instantiate a new dictionary object by passing a name. The motive is to use the function across different dictionaries. The problem is that the vba compiler won't compile the dictionary Name as it complains of a type mismatch.
In brief the function and code looks something like this: pass the name of the dictionary object I want to access, pass the operation I want to do, and an optional value.
Public Function GenericDictionary(dictName As String, dictMethod As String, optional dictValue as String ) As DictRtn
Select Case dictMethod
Case "instantiateDict"
Static dictName as Scripting.Dictionary
Set collectionName = New Scripting.Dictionary
……
Update DictRtn with something here….
….
End Select
return something here...
End Function
The complier won't accept the DictName in the Static statement. I believe I can understand why the type error is generated, but I need to insert the actual name that I pass with dictName and then have it compile to instantiate. I've attempted to do a DoCmd.rename, but the complier complains of undefined variables (ie DoCmd.rename dictName, Scripting.Dictionary, dictDefaultName) where dictDefaultName is something that I can predefine as a Scripting.Dictionary object.
Any suggestions or hints on how to get the compiler to type cast a string to a Scripting.Dictionary object? Suggestions on how to properly do the DoCmd Statement?
Thanks for any suggestions or help.
David