Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:28:10+00:00 2026-05-26T05:28:10+00:00

I am getting the following message when trying to return a new object to

  • 0

I am getting the following message when trying to return a new object to VBA from my Visual Foxpro COM server.
“Run-time error ‘-2147417851 (80010105)’:

Method ‘ReturnObject’ of object ‘Itestclass’ failed”

If I remove the “Dim … As” line the error goes away but then I lose intellisense for the COM object.

This is the VBA code:

Sub Test()

'' Removing the following line gets rid of the error but loses intellisense for the COM object
Dim objTest As testcom.TestClass

Set objTest = CreateObject("TestCOM.TestClass")
Set objNew = objTest.ReturnObject   '' This is the line that causes the error

End Sub

I have created a link to the TestCOM type library in Tools > References

Here is the Visual Foxpro (VFP) code:
The COM server is being built as an out of process EXE. If I build it as an inprocess .DLL then the VBA code causes Excel to crash.

DEFINE CLASS ObjectToReturn AS SESSION OLEPUBLIC

ENDDEFINE

DEFINE CLASS TestClass AS SESSION OLEPUBLIC

FUNCTION ReturnObject

    RETURN CREATEOBJECT("ObjectToReturn")

ENDFUNC

ENDDEFINE

I have tried changing the RETURN CREATEOBJECT(“ObjectToReturn”) to RETURN CREATEOBJECT(“CUSTOM”) but the problem persists.

Please advise how I can get rid of this error without losing the intellisense for the COM object in VBA. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:28:11+00:00Added an answer on May 26, 2026 at 5:28 am

    I don’t know why you are going through such difficulties… This should be able to help you… You can define your class as OlePublic and set some properties on it like the samples at the top. You can set these properties anywhere through the other functions that are not HIDDEN.

    If you need to are trying to get at certain elements OF some other “object”, try creating an instance of the object and stick it into a property on the OlePublic class… see my method

    DoSomethingElse

    which does a simple scatter NAME call to the “SomeObject” property of the class. Even though you are not explicitly returning it, it should be visible from within your creation of it from VB…

    DEFINE CLASS VFPClassForVB as Session  OLEPublic
      cTmpFiles  = ""
      cCOMUser  = ""
      SomeObject  = ""
    
      FUNCTION Init()
        */ Who is user...  always ignore the machine....
        This.cCOMUser  = SUBSTR( SYS(0), AT( "#", SYS(0)) +1 )
        This.cTmpFiles  = "somepath\"
    
        */ Unattended mode... any "MODAL" type dialog will throw error / exception
        SYS(2335, 0 )
    
        */ ALWAYS HAVE EXCLUSIVE OFF FOR COM!!!
        SET EXCLUSIVE OFF
    
        */ ALWAYS HIDE DELETED RECORDS!!!
        SET DELETED ON
      ENDFUNC 
    
      */ Error handler at the CLASS level will always be invoked
      */ instead of explicit ON ERROR or TRY/CATCH handlers...
      FUNCTION xError(nError, cMethod, nLine)
        lcMsg  = "User: " + SYS(0) + "  Tmp:" + SYS(2023);
            + "  Method: " + cMethod + "  Error: " + STR( nError,5);
            + "  Line: " + STR( nLine, 6 )
        STRTOFILE( lcMsg, This.cTmpFiles + "COMLog.txt" )
    
        */ NOW, throw the COM Error...
        COMReturnError( cMethod + '  Error:' + str(nError,5);
            + '  Line:' + str(nline,6);
            + '  Msg:' + message(), _VFP.ServerName )
      RETURN 
    
    
      HIDDEN FUNCTION SomeOtherFunction( lcWhat String,;
                         lnThing as Integer ) as String
    
        */ Do something
        RETURN 1
      ENDFUNC 
    
      */ Another completely visible function direct form VB
      FUNCTION DoSomethingElse( SomeParameter as String ) as String
        USE SomeTable
        */ Now, this object should be visible as a direct property in VB
        SCATTER MEMO NAME This.SomeObject
      ENDFUNC 
    
    ENDDEFINE 
    

    Your VB side, even from your sample…

    Sub Test()
    Set objTest = CreateObject("MySampleProject.VFPClassForVB")
    objTest.DoSomethingElse( "I dont care" )
    dim Something as objTest.SomeObject.ColumnFromTable  
    End Sub
    

    You can create as many OlePublic classes in your in-code class libraries that you want to expose and just create those instances as needed. Let me know if this helps you get closer and we’ll try to keep working it out.

    I’ve tried all sorts of samples, but looking at what you have of the object where both are VFP OleObject entries, each is exposed, and can be created individually. You don’t need to create one to create the other.

    Is there some reason SPECIFIC you are trying to create one object from another? You can have one object expose a bunch of methods and properties to perform whatever you need from VFP.

    If you want to have multiple object classes exposed, and under a central control, you can always create your primary object for communication and have IT create an instance of each “other” class on it. Then, expose methods on your main class to handle the communications between them to act out whatever it is you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following message when trying to create a new Silverlight application
I'm getting the following error when trying to convert HL7v3 to HL7v2 The message
I'm getting the error message when running the following code from a C# console
I was getting the following error message while trying to debug my code: Not
I am getting the following error when trying to send an email message where
I am getting the following error message when trying to execute a GET REST
Am getting following error message on calling WCF service: The formatter threw an exception
I am getting following error message when using Doctrine ORM in Codeigniter. ( !
We’re getting the following error message when we click on Search Settings for a
I'm getting the following error message and I can't seem to figure out the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.