Solved

Heirarchial query with MSHFLexGrid not working

Posted on 2010-11-08
5
485 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

813 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

10 Experts available now in Live!

Get 1:1 Help Now