Results 1 to 2 of 2

Thread: Urgent

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    11

    Lightbulb

    Hi..can anyone help me to solve the code below...it is related to search function by using ado control.. i think there something wrong of the code of linkage of the database.. its doesnt work well.. it always search nothing.. i really no idea how to solve it.. please give me a hand..!! and i want the data display on the data grid.. so is it the code correct..

    Private Sub cmdSearch_Click()
    'This function searches for a category which is specified
    by the user
    Dim CriteriaOk As Boolean
    Dim sql As String
    Dim strQuote As String
    strQuote = Chr$(34) 'Assigns the double quote character
    to a variable
    CriteriaOk = CheckSearchCriteria
    If CriteriaOk = True Then
    sql = "SELECT Category.CategoryID,
    Category.CategoryName, Category.BillingType,
    Category.Description, Category.Notes " & _
    "FROM Category " & _
    "WHERE (((Category.CategoryName) LIKE " &
    strQuote & "*" & txtSCompanyName.Text & "*" &
    strQuote & "))"
    datCategory.RecordSource = sql

    End If
    search (sql)
    End Sub


    Private Sub search(sql As String)
    Set rs = New ADODB.Recordset
    'rs.Open "Category", cn, adOpenForwardOnly,
    adLockReadOnly
    rs.Open sql, cn, adOpenKeyset, adLockOptimistic
    If rs.EOF And rs.BOF Then
    MsgBox "Match(es) not found", vbInformation +
    vbOKOnly, "Search Result"
    End If

    End Sub


    Private Function CheckSearchCriteria() As Boolean
    Dim Errormsg As String
    Dim quote As String
    quote = Chr$(34)
    If txtSCompanyName = "" Then
    Errormsg = MsgBox("Please Enter A Category Name.",
    vbExclamation + vbOKOnly, "Invalid Data")
    txtSCompanyName.SelStart = 0
    txtSCompanyName.SelLength = Len(txtSCompanyName)
    txtSCompanyName.SetFocus
    Exit Function
    End If
    If InStr(txtSCompanyName, quote) > 0 Then
    Errormsg = MsgBox("Double Quotes(" & quote & ") are
    not allowed om Category Name", vbExclamation +
    vbOKOnly, "Invalid Data")
    txtSCompanyName.SetFocus
    txtSCompanyName = ""
    CheckSearchCriteria = False
    Exit Function
    End If

    CheckSearchCriteria = True
    End Function

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Why are you setting the recordsource of the data control, then using a different ADO recordset to find out whether you will get results or not? Also, I am assuming CN is a valid connection as well....

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