[RESOLVED] Seach a Datagrid with Adodc
Hi again. I've searched the forums but cant seem to find an answer. Im using a datagrid with an adodc to get data from an access table. What I want to do is search the datagrid for a specific name entered into a textbox. How can that be done?
Thanks in advance.
Re: Seach a Datagrid with Adodc
You might do something like:
Code:
Private Sub Command1_Click()
With Adodc1.Recordset
.Find "[" & strTarget & "] = '" & Text1.Text & "'", , _
adSearchForward, adBookmarkFirst
If .EOF Then
MsgBox "Not found"
Else
MsgBox "Found at record " & CStr(.AbsolutePosition)
End If
End With
End Sub
... where strTarget is the field to search. If practical just hardcode it in the search expression. This will move the "current row" in the datagrid however.
Alternatively you might use:
Code:
Private Sub Command2_Click()
Dim rsCopy As ADODB.Recordset
Set rsCopy = Adodc1.Recordset.Clone(adLockReadOnly)
With rsCopy
.Find "[" & strTarget & "] = '" & Text1.Text & "'", , _
adSearchForward, adBookmarkFirst
If .EOF Then
MsgBox "Not found"
Else
MsgBox "Found at record " & CStr(.AbsolutePosition)
End If
.Close
End With
End Sub
Searching all fields would require you to loop through the Recordset for each field of the desired type until you hit a match.
Re: Seach a Datagrid with Adodc
Thanks that worked great :D