HELP ME TO CREATE MY OWN LIBRARY SYSTEM I NEED TO LEARN EDIT, DELETE, SEARCH, SAVE.
IF ANYONE CAN HELP ME???
THANK YOU IN ADVANCE!!!

Dani AI

Generated

The problem in 's snippet is that setting Recordset.Filter multiple times simply replaces the previous filter, so only the last condition actually runs. As hinted, combine criteria into one filter string or — more reliable for multi-field and partial matches — run a SELECT WHERE query against the data source and rebind/refresh the ADODC. Also be careful to escape single quotes in user input to avoid syntax errors.

Example: build a safe search SQL and refresh the ADODC (wildcard depends on the provider — Access/Jet default uses *, SQL Server and Access ANSI-92 use %):

Dim q As String
q = Replace(Trim(txtSearch.Text), "'", "''")   ' escape single quotes

If q = "" Then
  Adodc1.RecordSource = "SELECT * FROM Books"
Else
  ' For Access (ANSI-89): use '*' as wildcard; for SQL Server or ANSI-92 use '%'
  Adodc1.RecordSource = "SELECT * FROM Books WHERE Call_No LIKE '*" & q & "*' OR Book_Name LIKE '*" & q & "*' OR Author LIKE '*" & q & "*' OR ISBN_No LIKE '*" & q & "*'"
End If

Adodc1.Refresh

Common patterns for save/edit/delete (using the ADODC Recordset):

' Add
With Adodc1.Recordset
  .AddNew
  .Fields("Call_No").Value = txtCallNo.Text
  .Fields("Book_Name").Value = txtBookName.Text
  .Update
End With
Adodc1.Refresh

' Edit (find then edit)
With Adodc1.Recordset
  .Find "Call_No='" & Replace(txtCallNo.Text,"'","''") & "'"
  If Not .EOF Then
    .Edit
    .Fields("Book_Name").Value = txtBookName.Text
    .Update
  End If
End With
Adodc1.Refresh

' Delete
With Adodc1.Recordset
  .Find "Call_No='" & Replace(txtCallNo.Text,"'","''") & "'"
  If Not .EOF Then .Delete
End With
Adodc1.Refresh

Notes and troubleshooting: make sure the grid is bound to the ADODC and call Adodc1.Refresh (and refresh the grid) after changing the RecordSource or applying a filter. Use the correct delimiters for field types (no quotes for numeric, # for Access dates). For large tables prefer server-side WHERE queries with indexed fields rather than client-side Filter. Always escape user input (or use parameterized commands) and confirm destructive actions (DELETE) before executing.

Recommended Answers

All 3 Replies

hi jhai salvador., how about search Button i use .filter but the datagrid didn't show the record i search...

Private sub cmdSearch_Click()
with adodc1
.refresh
.recordset.filter = "Call_No='" & txtSearch.text & "'"
.recordset.filter = "Book_Name='" & txtSearch.text & "'"
.recordset.filter = "Author='" & txtSearch.text & "'"
.recordset.filter = "Date_Published='" & txtSearch.text & "'"
.recordset.filter = "ISBN_No='" & txtSearch.text & "'"
.recordset.filter = "Book_Type='" & txtSearch.text & "'"

If Adodc1.recordset.EOF then
    msgbox "Book Record Not Found,Try Again!",vbOkOnly
else
    msgbox "Record Found!"vbInformation
end if
End with
end Sub

Heres a sample on how to use filter property.

recordset.Filter = "Call_No='" & txtSearch.text & "' OR Book_Name='" & txtSearch.text & "'"

you can read more here:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.