Solved

Heirarchial query with MSHFLexGrid not working

Posted on 2010-11-08
5
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

756 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