hi, im new in vb6
how to search in datagrid where every keyword you type wil display the record
found in database? here's my code in saving
pls ned help here....this is our thesis
God Bless>thanks.

Sub search()
'search if student is registered then
With ado
    .ConnectionString = connectdb
    .RecordSource = "Select * from info where Barcode = '" & Text2 & "'"
    .Refresh

    If .Recordset.RecordCount > 0 Then
    Text3 = ado.Recordset!Barcode
    Text4 = ado.Recordset!fname
    Text5 = ado.Recordset!lname
    Text6 = Date

'student attendance check
    Call add

 End If




End With


End Sub

 Public Sub add()
'save to attendance record
With adoadd.Recordset
.AddNew
!Barcode = Text3
!First_Name = Text4
!Last_Name = Text5
!Date = Text6
.Update
MsgBox "save", vbInformation, "message"

Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text6 = ""
End With
DataGrid1.Refresh
End Sub

Recommended Answers

All 6 Replies

how to search in datagrid where every keyword you type wil display the record
found in database?

You want to search in datagrid or search record in database?

yes, thats it,like if i type on the txtbox automatically display on the datagrid
but dont know how to code it.
can u help me?

Ok. So when you type on textbox then there are data display on datagrid.
Use textbox change event to make searching every you type a word on textbox.
This is an example of searching using datagrid. Modified as you needed.

Private Sub Text1_Change()
 Set rs = New ADODB.Recordset
        rs.CursorType = adOpenDynamic
        rs.LockType = adLockOptimistic
        rs.Open "SELECT * FROM Login where fname  like " & "'%" & Text1.Text & "%'", Conn, , , adCmdText

    Set DataGrid1.DataSource = rs
    DataGrid1.Columns(0).Width = 2000
    DataGrid1.Columns(1).Width = 2000

    DataGrid1.AllowAddNew = False
    DataGrid1.AllowArrows = True
    DataGrid1.AllowDelete = False
    DataGrid1.AllowUpdate = False
End Sub

thank you so much, it works.

You're welcome.
Don't forget to mark this thread as Solved.
Happy Coding.

Hi,
This may be useful to find data from Grid.
Please find attached project.
It will be able to find and replace the text from MSFlexGrid's Cells

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.