Search button in Master-Detail form

Posted on 2002-04-24
Last Modified: 2012-08-13
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.mdb")
SQLQuery = "SELECT * FROM Customers"
Set rsCustomers = dbOrders.OpenRecordset(SQLQuery)
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(SQLQuery)
txtFields(0) = rsCustomers.Fields("CustID")
txtFields(1) = rsCustomers.Fields("Name")
txtFields(2)= rsCustomers.Fields("Phone")
End Sub

**************Master-Detail 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;Data

  Set rsCustomers = New Recordset
  rsCustomers.Open "SHAPE {select CustID,Name,Phone from Customers} AS ParentCMD APPEND

({select CustID,ProdID,Quantity,Total 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
  Set grdDataGrid.DataSource = rsCustomers("ChildCMD").UnderlyingValue
  mbDataChanged = False
End Sub

Private Sub CustomerSearch_Click()
End Sub
Question by:nickos_balabanis

Expert Comment

ID: 6965450
Why not use the Where clause in
"SHAPE {select CustID,Name,Phone from Customers} AS ParentCMD ..

"SHAPE {select CustID,Name,Phone from Customers WHERE Name LIKE '*" & txtFields(1) & "*'"} AS ParentCMD

Expert Comment

ID: 6965507
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.


Accepted Solution

Death-Speak earned 300 total points
ID: 6965626
I've used this before:

rsCustomers.Find " [some_field] = '" & strSomeStr & "'"

If its a date replace the 's with #s and if its a number remove the 's.

Hope this helps.

Author Comment

ID: 6968852
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 & "*'"

Expert Comment

ID: 6968877
Great! Glad it worked for you.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now