Consulting

Results 1 to 4 of 4

Thread: User-defined type not defined

  1. #1
    VBAX Regular
    Joined
    Nov 2007
    Posts
    19
    Location

    User-defined type not defined

    Hi,

    The code below works fine in my version of Excel but if I try to run on multiple other versions on different computers I get this error

    Compile error:
    User-defined type not defined

    [vba]
    Dim cn, strSQL, rst, i
    Set cn = New ADODB.Connection
    cn.Open myConnStr
    i = 2
    strSQL = "select * from table"
    Set rst = cn.Execute(strSQL)
    Do While Not rst.EOF
    With ActiveSheet
    ActiveSheet.Cells(i, 1).Value = rst(1)
    ActiveSheet.Cells(i, 2).Value = rst(2)
    ActiveSheet.Cells(i, 3).Value = rst(3)
    End With
    i = i + 1
    rst.MoveNext
    Loop

    cn.Close
    Set cn = Nothing
    [/vba]

    The problems occurs on this line

    [vba]New ADODB.Connection
    [/vba]

    I have looked at the References for the VBAProject on the computer where it is not working and there are no references that say they are missing.

    I have looked for the ADO type library but cant seem to locate it on the list - Does anybody know the exact name used?

    I realise this problem exists more than once on this forum but cant seem to get my example to work. Can anybody help with this please.

    Many thanks in advance

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Look for Microsoft ActiveX Data Objects 2.n Library
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Nov 2007
    Posts
    19
    Location
    Yep that seems to have done the trick. I have used the Microsoft ActiveX Data Objects 2.8 Library assuming that this will work on all machines. I have tested it on several machines and it seems to work fine.

    Many thanks

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Have a look at this KB Item
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •