Still Running VB6? You're Not Alone
Despite being officially retired, Visual Basic 6 continues to power countless line-of-business applications around the world. If you're maintaining one of these systems, you know that runtime errors in VB6 can be cryptic and difficult to diagnose — especially without modern debugging tools. This guide covers the most common VB6 runtime errors and how to resolve them.
Error 9: Subscript Out of Range
Cause: You're trying to access an array element or collection item using an index that doesn't exist.
Common triggers:
- A zero-based array accessed with index starting at 1 (or vice versa)
- A dynamic array that wasn't
ReDim'd before use - Accessing a worksheet or workbook by name that doesn't exist (in Office automation)
Fix: Always check array bounds with LBound() and UBound() before iterating. Use Option Base 0 or Option Base 1 consistently across your project.
Error 91: Object Variable Not Set
Cause: You're trying to use an object variable that is Nothing — it was never assigned or was set to Nothing explicitly.
Fix: Always check object variables before use:
If Not (myObject Is Nothing) Then
myObject.DoSomething
End If
Also ensure you're using Set when assigning objects: Set myObject = New MyClass.
Error 13: Type Mismatch
Cause: An operation is attempted on a variable whose type doesn't match what's expected — e.g., passing a string where a number is required.
Fix: Use explicit conversion functions: CInt(), CLng(), CDbl(), CStr(). Validate user input before converting:
If IsNumeric(txtAge.Text) Then
Dim age As Integer
age = CInt(txtAge.Text)
End If
Error 429: ActiveX Component Can't Create Object
Cause: VB6 can't instantiate a COM/ActiveX object. The component may not be registered on the machine.
Fix:
- Re-register the DLL using
regsvr32 MyComponent.dllfrom an elevated command prompt - Check that the component is installed at the correct path
- On 64-bit Windows, use the 32-bit version of regsvr32:
C:\Windows\SysWOW64\regsvr32.exe
Error 3021: No Current Record (DAO/ADO)
Cause: You're trying to read from a Recordset that has no rows, or the cursor is positioned before the first or after the last record.
Fix: Always check EOF and BOF before accessing fields:
If Not (rs.EOF Or rs.BOF) Then
txtName.Text = rs!CustomerName
End If
Error 5: Invalid Procedure Call or Argument
Cause: A built-in function received an argument outside its valid range (e.g., Mid("hello", 0, 3) — Mid starts at position 1, not 0).
Fix: Consult the VB6 documentation for valid argument ranges and add input validation before calling built-in string/math functions.
General Debugging Tips for VB6
- Use Break on All Errors (Tools → Options → General → Error Trapping) while developing
- Add
Debug.Printstatements to trace variable values in the Immediate window - Wrap risky sections in
On Error GoTohandlers with descriptive logging - Use the Watch window to monitor object state during execution
A Note on Long-Term Maintenance
While these fixes will keep your VB6 app running, they are tactical solutions. If your application is business-critical, consider building a migration roadmap to VB.NET or C#. Each runtime error you fix today is an opportunity to evaluate whether that component could be rewritten in a supported framework.