View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
quartz[_2_] quartz[_2_] is offline
external usenet poster
 
Posts: 441
Default Removing reference generates type mismatch error

Thanks Philip, yes I always forget about late binding, but I think my current
work around will prevent me from having to change my code around at this
point...
Thanks for the tip...

"Philip" wrote:

Hi,

One easy solution is to use late-binding...when distributing accross
different versions (where you may have different versions of ADO installed)
it pays to use late-binding.

Then you won't need to add the reference - especially as you have completed
the development and no longer need the intellisense!

so instead of:

dim adoRS as new adodb.recordset, adoCN as new adodb.connection

use:
dim adoRS as object, adoCN as object

set adoRS=vba.createobject("adodb.recordset")
set adoCN=vba.createobject("adodb.connection")

this guaratees that if ado is installed theen vba will always instantiate
the one in the registry.

HTH

Philip

"quartz" wrote:

I am using Office 2003 on Windows XP.

When distributing programming solutions I have encountered a situation in
which one user has Office 2003 and another user of the same file has a
previous version of Office. All users have at least Office 2000 or greater.

I have a function that creates a reference to ADO programmatically and it
works fine, unless an Office 2003 user is the last user of the file. ADO
references will go forward, but not backward. So I need to remove the ADO
reference on exit, then re-reference ADO on open each time.

I can work all this out, except my removal function gives me a "Type
mismatch" error.

1) My functions follow, can someone please correct my code and/or post code
of your own to deal with this?

2) Also, does it seem as though my approach will thoroughly fix my issue?

Public Function ADOReferenceAdd()
'PROGRAMMATICALLY ADD AN ADO REFERENCE
On Error Resume Next
ActiveWorkbook.VBProject.References.AddFromFile "C:\Program Files\Common
Files\System\ado\msado15.dll"
On Error GoTo 0
End Function

Public Function ADOReferenceRem()
'PROGRAMMATICALLY REMOVE AN ADO REFERENCE
On Error Resume Next
ActiveWorkbook.VBProject.References.Remove "C:\Program Files\Common
Files\System\ado\msado15.dll" '<type mismatch error here (fix line wrap)
On Error GoTo 0
End Function

Thanks much in advance for your assistance.