Results 1 to 3 of 3

Thread: SQL problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    476

    SQL problem

    I am getting the follwing error:

    Compile Error:

    User-defined type not defined

    VB Code:
    1. Private Sub Go_search()
    2.    Dim sSQL As String
    3.    Dim cn As ADODB.Connection     <--- Error here
    4.    Dim rs As ADODB.Recordset
    5.    Dim Str As String, itmX As ListItem
    6.    
    7.    Set cn = New ADODB.Connection 'weve declared it as a ADODB connection lets set it.
    8.    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    9.       "Data Source= " & App.Path & "\ADDBK.mdb" 'this is the connection string.
    10.    cn.Open
    11.    Set rs = New ADODB.Recordset
    12.    
    13.    sSQL = "SELECT Name, Phone, Keywords, Com_No "
    14.    sSQL = sSQL & "FROM Company "
    15.    
    16.    If Len(Text1(0).Text) > 0 Then
    17.       Str = "WHERE Keywords like %" & "'" & Text1(0).Text & "%'"
    18.    End If
    19.    
    20.    If Len(Text1(1).Text) > 0 Then
    21.       If Len(Str) = 0 Then
    22.          Str = "WHERE Name like " & "'" & Text1(1).Text & "%'"
    23.       Else
    24.          Str = Str & "AND Name like " & "'" & Text1(1).Text & "%'"
    25.       End If
    26.    End If
    27.      
    28.    sSQL = sSQL & Str
    29.    Set rs = cn.Execute(sSQL)
    30.    
    31.    Do Until rs.EOF = True
    32.       Set itmX = ADLV.ListItems.Add(, , rs.Fields("Name"))
    33.       itmX.SubItems(1) = rs.Fields("Phone")
    34.       itmX.SubItems(2) = rs.Fields("Keywords")
    35.       itmX.SubItems(3) = rs.Fields("COM_No")
    36.    
    37.       rs.MoveNext
    38.    Loop
    39.        
    40.    rs.Close
    41.    Set rs = Nothing
    42.    Set cn = Nothing
    43.        
    44.    ADLV.Sorted = True
    45.    ADLV.SortKey = 1
    46.    ADLV.SortOrder = lvwAscending
    47.    ADLV.Refresh
    48. End Sub

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL problem

    Reference Microsoft ActiveX Data Object 2.something...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: SQL problem

    You have to add a REFERENCE and click:
    VB Code:
    1. Microsoft ActiveX Data Objects 2.x Library

    the latest MDAC is 2.8

Posting Permissions

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



Click Here to Expand Forum to Full Width