Solved

Search button in Master-Detail form

Posted on 2002-04-24
5
312 Views
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

Source=C:\Orders.mdb;"
 
  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
  Next
  Set grdDataGrid.DataSource = rsCustomers("ChildCMD").UnderlyingValue
  mbDataChanged = False
End Sub


Private Sub CustomerSearch_Click()
???
End Sub
0
Comment
Question by:nickos_balabanis
5 Comments
 
LVL 2

Expert Comment

by:corvanderlinden
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
0
 
LVL 3

Expert Comment

by:n_narayanan
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.

Narayanan
0
 

Accepted Solution

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

rsCustomers.MoveFirst
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.
0
 

Author Comment

by:nickos_balabanis
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 & "*'"
0
 

Expert Comment

by:Death-Speak
ID: 6968877
Great! Glad it worked for you.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Object Property from VBA Module in Excel 2010 2 39
Visual Studio 2005 text editor 10 48
vbModal 12 66
Copy a range from 1..n excel sheets to one destination sheet 2 66
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

713 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