is there a way to search database viwable in datagrid view by selecting rows through a combo box, values trough a text box and display resoult in label? here is the code that doesnt work:

Private Sub Command1_Click()
'populate datagrid trough textboxes
 DBGrid1.Columns(0).Text = Text1.Text
 Text1 = ""
 DBGrid1.Columns(1).Text = Text2.Text
 Text2 = "" !
 DBGrid1.Columns(2).Text = Text3.Text
 Text3 = ""
 DBGrid1.Columns(3).Text = Text4.Text
 Text4 = ""
 DBGrid1.Columns(4).Text = Text5.Text
 Text5 = ""
 DBGrid1.Refresh
End Sub

Private Sub Command4_Click()
'button for search
'MsgBox ("Your Name is " & Text6.Text)
With Data1.Recordset

If Combo1.Text = "id" Then
Label6 = ("[id]like" & Text6.Text)
.FindFirst = Label6
If .NoMatch Then
MsgBox " No id found!"
Else
Data1.Recordset.Filter = ("[name]" & Text6.Text)
End If

ElseIf Combo1.Text = "name" Then
Label6 = ("[name]like" & Text6.Text)
.FindFirst Label6
If .NoMatch Then
MsgBox " No name found!"
Else
Data1.Recordset.Filter = ("[sname]" & Text6.Text)
End If

ElseIf Combo1.Text = "sname" Then
Label6 = ("[sname]like" & Text6.Text)
.FindFirst Label6
If .NoMatch Then
MsgBox " No sname found!"
Else
Data1.Recordset.Filter = ("[adress]" & Text6.Text)
End If

ElseIf Combo1.Text = "adress" Then
Label6 = ("[adress]like" & Text6.Text)
.FindFirst Label6
If .NoMatch Then
MsgBox " No adress found!"
Else
Data1.Recordset.Filter = ("[phone]" & Text6.Text)
End If

ElseIf Combo1.Text = "phone" Then
Label6 = ("[phone]like" & Text6.Text)
.FindFirst Label6
If .NoMatch Then
MsgBox " No phone found!"
Else
Data1.Recordset.Filter = ("[phone]" & Text6.Text)
End If
End If
Text6.SetFocus
End With

End Sub

Private Sub Form_Load()
'call sub to clear all textboxes
Call Clear
'populate combobox
Combo1.AddItem "id"
Combo1.AddItem "name"
Combo1.AddItem "sname"
Combo1.AddItem "adress"
Combo1.AddItem "phone"
End Sub

Private Sub Clear()
'sub to clear textboxes
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub !

myform.jpg

I did it! hooray!!
note for anubody with the same problem: we can not search database without writing sql querys ;) :)!

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.