Inspect the value, not only the declaration
Capture the failing statement and log TypeName, VarType and a safe representation of each input. A Variant may contain a number, string, date, object, Empty, Null or an array despite appearing harmless in the debugger.
- Handle
Nullexplicitly before conversion; it is not an empty string or zero. - Separate missing/empty input from valid zero values.
- Replace implicit conversions with checked, intentional conversions.
- Inspect database field types and parameter types at the failing row.
- Confirm the declared COM or API return type matches the installed interface.
Why it can be environment-dependent
| Dates and decimals | Locale changes how ambiguous strings are parsed. |
|---|---|
| Database records | One row may contain Null, unexpected text or a wider numeric value. |
| COM/API result | A component version can return a different Variant subtype or interface. |
| Control values | List and text controls may expose sentinel values before selection. |
Reproduce with the exact input and regional settings before changing broad conversion rules. Validate at the system boundary so invalid data does not travel deep into calculations.
For object initialization failures see error 91; for recordset and provider behavior use ADO troubleshooting. The VB6 pillar provides the wider system context.