Solved

Heirarchial query with MSHFLexGrid not working

Posted on 2010-11-08
5
483 Views
Last Modified: 2012-06-21
Hello experts,
I am having a problem with a pretty complex query at least its complex to me.
I am using vb6 with an Access DB.    
There are 2 tables, one called Person and one called Pets.
The person table has 2 fields that I am using in the query, they are PatientID and ContactLastName.
The Pet table I am using has 2 fields called PetID and PetName.
I am trying to display in a MSHFlexgrid, one column showing the last Name and PatientID from the person table,  and the Pet name and PetID from the Pets table.  
this is a veterinary application and i want to display how many pets from the (Pets) table are associated to a particular PatientID from the (person) table.
dont be confused my the term patientID,  that is actually the owners of the pets. I guess I should have called it ClientID but I didnt.

Smith          Spot
                   Rover
                   Lassie

Jones          Max
                   Jack
                    Lady
something like that...
Here is the query that I tried,  but had no success:

Dim NameSearch As String     ' name of search string
NameSearch = shape(("SELECT ContactLastName, PatientID From person) WHERE PatientID = 329215917))APPEND((SELECT PetName,PetID FROM Pets WHERE PetID = 'KnoS712')) AS mshflexgrid1 RELATE PetID To PatientID"))
Adodc1.RecordSource = NameSearch
Adodc1.Refresh
End Sub

I think it may be because of my mess of bracketing or something,   I need someone smarter than me, Hope you can help !!!
0
Comment
Question by:Stevenj2
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:VBClassicGuy
ID: 34088635
Unless I'm reading it wrong, there is no correlation between PatientID and PetID. In your example, you have a Patient ID of 329215917 and a PetID of KnosS712. How do you associate specific pets to specific patients?
If there IS a correlation, just use an inner join on the related fields to pull out all pets for a specific patient.
0
 

Author Comment

by:Stevenj2
ID: 34088846
The patient ID is actually a client ID just called patientID. I made it that way a long time ago and then changed direction.   the correlation between the 2 is patientID and PetID,   one patient can have many pets with unique pet id's.  and I used those numbers only  to hard code it into the query to make it work.  
And Normally I would use some other input like a text box or something. they are valid PatientID's  and Pet ID's.
The only thing I guess i didnt make clear was that I dont kow how to do inner joins.thats why Im here loking for help.    
0
 

Author Comment

by:Stevenj2
ID: 34088880
I attached this table to show the patient and pet id's in both tables.   think of the patientID being the owner and the petID being the ID's of all the pets owned by a specific owner.  I would like to show that in a MshFlexgrid.
Person-and-Pet-database-tables.JPG
0
 
LVL 14

Accepted Solution

by:
VBClassicGuy earned 500 total points
ID: 34093179
I'm not used to binding my FlexGrid, I just read the DB and fill an unbound FlexGrid. I'd use a statement like:
SQL$ = "SELECT Person.ContactLastName, Person.PatientID, Pets.PetName AS [ThePetName]"
SQL$ = SQL$ & " FROM Person INNER JOIN Pets ON Person.PatientID = Pets.PatientID"
SQL$ = SQL$ & " WHERE Person.PatientID='" & ThePatientName & "'"
rs.Open SQL$, YourDB, adOpenForwardOnly, adLockReadOnly

Then loop through the record set and build rows for the grid.
 
0
 

Author Closing Comment

by:Stevenj2
ID: 34107898
I do appreciate the responses,  however i am not experienced in this at all and was looking for some more detailed examples as I stated in my response.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

706 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

19 Experts available now in Live!

Get 1:1 Help Now