35

I'm trying to run a legacy VB6 application on my desktop (it doesn't have a user interface, being a command-line app), and when I do, I get a message box saying

Run-time error '4099':

Method '~' of object '~' failed

This means nothing to me; does anyone have an idea what is going wrong?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Cyberherbalist
  • 12,061
  • 17
  • 83
  • 121
  • what does the application do? Does it rely on any external library? Do you have the source code? – shahkalpesh Aug 19 '09 at 19:13
  • 1
    I do have the source code, which is a good thing. There did happen to be different versions of the supporting libraries, some dating back seven years, others much more recent, though they had all been built at the same time, originally. There had been no change to the underlying code, but different compiles evidently produced enough differences to cause the error. I'm sure it didn't help that the app runs on a workstation and the dll's run on a server. I recompiled all 4 supporting libraries, and then the app itself with these fresh dll's, and that did the trick. – Cyberherbalist Aug 19 '09 at 22:14

9 Answers9

19

That can happen when supporting libraries (dlls or ocxs) are not registered properly or the versions of the installed libraries are different (and incompatible) with the version the app was compiled against originally.

Make sure all dependent libraries are registered and the proper version.

You may have to recompile the app to make it work with newer versions of the supporting libraries.

DJ.
  • 16,045
  • 3
  • 42
  • 46
13

This message occurs when a Visual Basic 6 application makes a COM interface call which throws an exception (i.e. returns a failure HRESULT). In this case, VB6 jumps to an exception handler (as set by On Error). In the exception handler there is visible an object Err which contains details of the exception.

If the object implements ISupportErrorInfo, and it does actually support error info, and it did set error info, then Err.Description takes the string that is in the error info set by the object. Otherwise, Err.Description takes the string Method ~ of ~ failed.

IDK whether other versions of VB do the same thing; or if the message is also set in other scenarios besides the one I have just described.

M.M
  • 138,810
  • 21
  • 208
  • 365
3

Another cause can be when using automation, some minor-version mismatch of Office:

I have a legacy VB5+Access app (which i'm in the process of rewriting in Delphi and replacing all the automation mess with clean OpenDocument generation) that ran well on some systems and gave the error on others.

This error would happen when generating an Excel spreadsheet, and seemed harmless (except the annoyance and as it would show a dozen times the risk of user clicking 'Abort' in the middle) as if always clicking 'Ignore' everything worked as expected.

I eventually found the cause was the way Office 97 was installed:

The error would show up if the Office 97 setup sequence was:

  • Office 97 SR0 install CD
  • apply SR1 patch
  • apply SR2 patch

but not if it was installed with:

  • Office 97 SR1 install CD
  • apply SR2 patch

Doing an uninstall / reinstall with SR1 setup on the affected systems solved the problem.

2

I have VB6 SP6 and I can reproduce this behavior. In a fresh project, put this code into a form. The project runs normally with F5. Right click the project and select Publish then Build Outputs. This generates the error message.

Option Explicit

Public Sub Init()
    Dim blnErrorHandling As Boolean

    If False Then
        blnErrorHandling = True
    Else
        blnErrorHandling = False
End Sub

Now comment out the last four lines:

Option Explicit

Public Sub Init()
    Dim blnErrorHandling As Boolean

'    If False Then
'        blnErrorHandling = True
'    Else
'        blnErrorHandling = False
End Sub

You no longer get the error and the outputs are built normally. I was quickly adding in some error handling to locate the source of a crash and If False Then is perfectly valid. The MDAC checker said all was ok and a reboot didn't solve the problem.

Brian Leeming
  • 11,540
  • 8
  • 32
  • 52
  • You're right that `If False Then` is valid, but `If` without `End If` is not. Your first snippet wouldn't even compile. – mwolfe02 May 06 '11 at 15:12
  • Jeeze, I've been away from VB6 for so long and in my IDE the Compile on demand was checked. Adding the End If was the solution. Thanks for the answer! – Brian Leeming May 06 '11 at 15:38
2

In the VB6 IDE go to Tools->Options->Editor and clear Drag-and-Drop Text Editing feature

Thanks Matthew, you pointed me in the right direction, though I don't fully understand your issues

I have an old VB6 project to rework, now able to edit and recompile OK on Windows 10, after the usual trauma of reregistering all the .ocx files. I run the VB6 through a shortcut with Properties->Advanced->Run As Administrator

This error was persistent, popping up every time I started the VB6 IDE

After reading Matthews post, I cleared the Drag-and-Drop Text Editing feature

Shut down, restart VB6 and the error had gone

Re-enabled Drag-and-Drop and still no error

(Still living with the Automation Element Not Found Error)

Ian Pedley
  • 21
  • 1
1

Windows 10;

Copy c:\windows\SysWOW64\COMMTB32.DLL

Past C:\Program Files (x86)\Microsoft Visual Studio\VB98\

it worked for me

0

For a VB6 program which is run as a command line application there is an extra stage required after compilation: the VB6 linker needs to be run on the executable to set it as a console program:

<VB6 dir>\LINK.EXE  /EDIT  /SUBSYSTEM:CONSOLE  <program>.exe

Failure to do this will give the Method '~' of object '~' failed error when the program is run.

Mon Calamari
  • 4,403
  • 3
  • 26
  • 44
yttyx
  • 1
  • 1
0

As per my experience, it is due to Microsoft Access Version.

My program was made in MS Office 2007 and installed newer version of MS Office. Thats why this error appears.

Sajjad
  • 1
  • Welcome to Stack Overflow! Though we thank you for your answer, it would be better if it provided additional value on top of the other answers. In this case, your answer does not provide additional value, since another user already posted that solution. If a previous answer was helpful to you, you should vote it up instead of repeating the same information. – Toby Speight Dec 12 '17 at 10:33
0

I had this error in my compiled program. It did not occur while debugging. I found out the real problem by looking at the value of Err.Number, of the raised error.

In my case the value was 32811, and it was caused by a call to Dictionary.Remove(key), where key was not in the dictionary. Debugging raised the same Err.Number but instead with the Err.Description "Method 'Remove' of object 'IDictionary' failed".

It seems that Err.Description gets messed up in the compiled program, for some reason in this case

symbiont
  • 1,428
  • 3
  • 21
  • 27