nickos_balabanis
asked on
Search button in Master-Detail form
Hello there. Here is the problem. I have made a Search button to locate records in a DB. It works fine in my 'Simple Form' project but I cannot do the same for the 'Master Detail Form'project (As you may recognize it is a VB6 wizard generated Form). Please help me!
**************Simple Form********************
Dim dbVideo As Database
Dim rsCustomers As Recordset
Private Sub Form_Load()
Set dbVideo = OpenDatabase("c:\Orders.md b")
SQLQuery = "SELECT * FROM Customers"
Set rsCustomers = dbOrders.OpenRecordset(SQL Query)
txtFields(0) = rsCustomers.Fields("CustID ")
txtFields(1) = rsCustomers.Fields("Name")
txtFields(2)= rsCustomers.Fields("Phone" )
End Sub
Private Sub CustomerSearch_Click()
SQLQuery = "SELECT * FROM Customers WHERE Name LIKE '*" & txtFields(1) & "*'"
Set rsCustomers = dbVideo.OpenRecordset(SQLQ uery)
txtFields(0) = rsCustomers.Fields("CustID ")
txtFields(1) = rsCustomers.Fields("Name")
txtFields(2)= rsCustomers.Fields("Phone" )
End Sub
**************Master-Detai l Form********************
Dim rsCustomers As Recordset
Private Sub Form_Load()
Dim db As Connection
Set db = New Connection
db.Open "Provider = MSDataShape;Data PROVIDER = Microsoft.Jet.OLEDB.4.0;Da ta
Source=C:\Orders.mdb;"
Set rsCustomers = New Recordset
rsCustomers.Open "SHAPE {select CustID,Name,Phone from Customers} AS ParentCMD APPEND
({select CustID,ProdID,Quantity,Tot al from Orders } AS ChildCMD RELATE CustID TO CustID) AS ChildCMD", db, adOpenStatic, adLockOptimistic
Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = rsCustomers
Next
Set grdDataGrid.DataSource = rsCustomers("ChildCMD").Un derlyingVa lue
mbDataChanged = False
End Sub
Private Sub CustomerSearch_Click()
???
End Sub
**************Simple Form********************
Dim dbVideo As Database
Dim rsCustomers As Recordset
Private Sub Form_Load()
Set dbVideo = OpenDatabase("c:\Orders.md
SQLQuery = "SELECT * FROM Customers"
Set rsCustomers = dbOrders.OpenRecordset(SQL
txtFields(0) = rsCustomers.Fields("CustID
txtFields(1) = rsCustomers.Fields("Name")
txtFields(2)= rsCustomers.Fields("Phone"
End Sub
Private Sub CustomerSearch_Click()
SQLQuery = "SELECT * FROM Customers WHERE Name LIKE '*" & txtFields(1) & "*'"
Set rsCustomers = dbVideo.OpenRecordset(SQLQ
txtFields(0) = rsCustomers.Fields("CustID
txtFields(1) = rsCustomers.Fields("Name")
txtFields(2)= rsCustomers.Fields("Phone"
End Sub
**************Master-Detai
Dim rsCustomers As Recordset
Private Sub Form_Load()
Dim db As Connection
Set db = New Connection
db.Open "Provider = MSDataShape;Data PROVIDER = Microsoft.Jet.OLEDB.4.0;Da
Source=C:\Orders.mdb;"
Set rsCustomers = New Recordset
rsCustomers.Open "SHAPE {select CustID,Name,Phone from Customers} AS ParentCMD APPEND
({select CustID,ProdID,Quantity,Tot
Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = rsCustomers
Next
Set grdDataGrid.DataSource = rsCustomers("ChildCMD").Un
mbDataChanged = False
End Sub
Private Sub CustomerSearch_Click()
???
End Sub
Remove this coding,
Private Sub CustomerSearch_Click()
???
End Sub
And try,
If two procedure are same name, vb will always take the last one. In your case it would have executed the last procedure.
Narayanan
Private Sub CustomerSearch_Click()
???
End Sub
And try,
If two procedure are same name, vb will always take the last one. In your case it would have executed the last procedure.
Narayanan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. This is what I wanted! Actually this technique selects all records and points you to the one you search for. My technique selects only the records matching the search criteria.
I improved it a bit. Now it can search using part of the field:
adoPrimaryRS.Find " [some_field] Like '*" & strSomeStr & "*'"
I improved it a bit. Now it can search using part of the field:
adoPrimaryRS.Find " [some_field] Like '*" & strSomeStr & "*'"
Great! Glad it worked for you.
"SHAPE {select CustID,Name,Phone from Customers} AS ParentCMD ..
"SHAPE {select CustID,Name,Phone from Customers WHERE Name LIKE '*" & txtFields(1) & "*'"} AS ParentCMD