Solved

Heirarchial query with MSHFLexGrid not working

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
pop out of webbrowser1 control vba6 5 25
File.Search issue 8 33
RAISERROR WITH NOWAIT 2 17
Access Web App or PowerApp 29 41
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 …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

829 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