Results 1 to 3 of 3

Thread: [RESOLVED] Seach a Datagrid with Adodc

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    10

    Resolved [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.

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    10

    Re: Seach a Datagrid with Adodc

    Thanks that worked great

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