Monday, February 13, 2012

Access Database ADO Reference Breaks Moving From Windows 7 to XP.

I first noticed this problem deploying software from my Windows 7 box to a customer's XP machines, that assigning an New ADO.Recordset object to a previously declared ADO.Recordset variable was raising a type mismatch error, which is the kind of thing that makes you go, "Hmmnn?"
- I found I could solve the error by changing the ADO reference to a different version, say from 2.5 to 2.8, and/or back again, and then recompiling the database, but that got tedious.
- Here's an article at Microsoft that explains what is going on.
- Here's the code I run at startup that resets the reference to 2.8, which shipped with XP, and it seems to have solved the problem for me...
Private Sub ResetADOReference()
On Error GoTo handler
   'remove ref, raises err 9 if not present
   References.Remove References("ADODB")
   'add reference
   'References.AddFromGuid "{00000206-0000-0010-8000-00AA006D2EA4}", 2, 6
   References.AddFromGuid "{2A75196C-D9EB-4129-B803-931327F72D5C}", 2, 8
   Exit Sub
handler:
   If err = 9 Then
      'subscript out of range
      Resume Next
   Else
      MsgBox err & " " & err.Description & vbCrLf & _
         "ADODB reference may be broken.", vbExclamation
   End If
End Sub
Article: Breaking change in MDAC ADODB COM components in Windows 7

No comments:

Post a Comment