none
Calling a Shared Function from a VB .Net DLL RRS feed

  • Question

  • I have a DLL named DatalayerManager.dll that I created using Visual Studio Express 2010. It exposes COM and I have been able to register it in MS Access 2010. The DLL has the following shared method:

        Public Shared Function GetInstance(ByVal pAlwaysOpen As Boolean) As BaseClasses.IDatalayer
            Try
                If mDataLayer Is Nothing Then
                    mDataLayer = New Datalayer(pAlwaysOpen)
                End If
                Return mDataLayer
            Catch ex As Exception
                Throw
            End Try
        End Function

    In an MS Access code module, I have declared:

    Dim mDatalayer As BaseClasses.IDatalayer

    Public Function Initialize()

        mDatalayer = DatalayerManager.Datalayer.GetInstance(False)

    End Function

    This does not compile - the error message is "Method or data member not found" and ".Datalayer" is highlighted.

    I change the code to this:

    Public Function Initialize()

        mDatalayer = Datalayer.GetInstance(False)

    End Function

    It compiles but when I run it I get a message that says "Runtime Error 424: Object Required."

    Any help would be greatly appreciated!

    Friday, April 13, 2012 3:00 AM

All replies

  • Hi Joe,

    Thanks for posting in the MSDN Forum.

    Where you defined the BaseClasses.IDatalayer?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 16, 2012 4:24 AM
    Moderator
  • Tom -

    BaseClasses.IDatalayer is in BaseClasses.DLL, which in turn is referenced by DatalayerManager.dll. The purpose of BaseClasses is to contain the interface and abstract classes. Normally in a .Net application, I reference BaseClasses and create a Datalayer class that inherits from BaseClasses.ADatalayer. In an attempt to get this to work with VBA, I created DatalayerManager that has the Datalayer runtime class.

    -joe

    Monday, April 16, 2012 4:33 AM
  • Hi Joe,

    Dose BaseClasses is a COM Visiable class?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, April 17, 2012 4:34 AM
    Moderator
  • Tom -

    Yes, it does.

    -joe

    Tuesday, April 17, 2012 4:36 AM
  • Hi Joe,

    I will involve some experts into this thread to see whether they can help you. There might be some time delay, thanks for your patience.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, April 18, 2012 5:52 AM
    Moderator
  • Thanks, Tom! I really appreciate it.
    Wednesday, April 18, 2012 3:36 PM
  • Hi Joe,

    Because you do not get an error on the "Dim mDatalayer as BaseClasses.IDatalayer" line of code, I am assuming that you have already added a reference to your DLL (In the VBA editor go to "Tools \ References")

    My first suggestion is to make sure that at the top of the VBA module you have the directive "Option Explicit". This will make force you to define all variables before using them. Without this line VBA (Access) will create a variable anything it can't find one. I think this is what is happening in your second example "mDatalayer = Datalayer.GetInstance(False)". Datalayer is not defined so VBA defines this as a variant which of course does not have the "GetInstance()" method.

    Assuming you have added the reference to your DLL, when you type "DatalayerManager." intellisence should show you the available methods and properties on the object. Within the VBA editor in Access you can also hit F2 ("View \ Object Browser") to open the Object Browser. From here you can see all of the objects. methods and properties that have been exposed to VBA.

    My guess (and it is just that) is that "mDatalayer = DatalayerManager.GetInstance(False)" will probably work.

    Best Regards,

    Donald M.
    Microsoft Online Community Support

    --------------------------------------------------------------------------------

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Wednesday, April 18, 2012 8:24 PM
  • Donald -

    It's been so long since I've done Access VBA, I'd forgotten that. Thanks.

    However, it still didn't work. I've uploaded the VB .Net solutions here:

    http://astutedata.com/files/DatalayerManager.zip

    I've added a Generator class in the hopes of getting it to work. The VBA code is:

    Option Compare Database
    Option Explicit

    Dim mDatalayer As BaseClasses.IDatalayer

    Public Function Initialize()
        Dim gen As DatalayerManager.generator
        
        Set gen = New DatalayerManager.generator
        Set mDatalayer = gen.GetInstance(False)
        Set mDatalayer = Nothing

    End Function

    Thanks!

    Thursday, April 19, 2012 4:00 AM
  • Hi Joe,

    Are you seeing any properties/methods/actions for the iDatalayer or Generator classes in VBA?
    One way to check is to go to the Object Browser and then select your library.
    The other say is to define a variable of the type (as you do with mDatalayer and gen) and then type the variable name followed by a dot (".") and see what appears for intelisence.

    If you see some properties, methods or actions, then there may be something different about the way you defined the function.

    If that that does not resolve the issue and you wish to pursue this further you should open a support incident. The following article should provide you with instructions on how to do this.
    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Best Regards,

    Donald M.
    Microsoft Online Community Support

    --------------------------------------------------------------------------------

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Thursday, April 19, 2012 7:09 PM