cloudlck
Apr 15th, 2000, 10:36 AM
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
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