-1

I am running some legacy VB6 code on a 64bit Windows 7 machine and am running into some weird errors.

my code blows up here:

enter image description here

with the message:

enter image description here

a whole section of code above this error handling is precededed by:

On Error GoTo ErrorTrap

ErrorTrap being my For Each loops seen above.

What causes this type mismatch?

jth41
  • 3,808
  • 9
  • 59
  • 109

2 Answers2

4

MyError has to be a Variant type: in VB6 For-Each enumeration has to be done using a Variant.

Use

Dim MyError As Variant

instead.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
  • 3
    Dimming as a Variant should only be the last resort. If this DBEngine is an ADODB Connection then MyError should be dimmed as ADODB.Error. `Dim MyError As ADODB.Error` This will improve performance over a variant, and let IntelliSense display the methods and properties available. – jac Jun 07 '13 at 16:02
2

If your code has anything to do with ADO then it could be the known VB6 ADO & Win 7 issue described here: http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/3a4ce946-effa-4f77-98a6-34f11c6b5a13. It seems that typelibs changed in Win7 Sp1 which could make VB6 apps compiled on prior platforms crash when run on Win 7 or apps compiled on Win 7 crash when run on prior platforms. The linked article provides some suggestions for solutions, the easiest of which if you have the source code is to switch to use late binding when viable.

James Evason
  • 101
  • 1
  • 4