I have a form with multiple subforms arranged as tabs. The main form is named Client_Intake_form, and contains a last name field for the head of the household as well as address information. The subform on a tab is called persons_subform. This tab contains information about individuals such as first and last name, age and other demographics. In the data it is common for the head of household last name to be different from the individuals that make up "the family" so the primary form is opened to head of household. The persons_subform may have multiple records on the tab and arrow keys are present to allow you to scroll through the family members.
I have a Name_search_form that I use to allow the user to search for persons in the database. It works fine to locate the correct family and populate the subform with the persons that make up the family but the person that shows up in the subform is the one with the lowest primary key ID rather than family member selected. I would like the search form to locate the correct family (on the main form) AND open the correct family member on the subform. The table relationship is as follows (disregard the extraneous relationship lines I have tried to hide; it's a one to many relationship of CLID to CL_ID):
My original idea was so do the primary search in the Name_search_Form on the primary key for the family name- 'CLID' and pass the primary key for the individual selected-'ID' as an openarg. If I set the WHERE statement to a fixed ID number, it works but limits the subform to that particular individual (you can't use the arrow keys to move to other family members).
Now I have tried to use a recordset to find the appropriate person but my code isn't working here either. I'm out of ideas.
This code works fine- it selects the appropriate family name and passes the individual's ID number as an openarg.
Code:
Private Sub CmboSearch_AfterUpdate()
' code from the name search form that grabs the CLID and ID from a combobox
Dim rs As Object
On Error GoTo Err_CmboSearch_AfterUpdate
DoCmd.OpenForm "Client_intake_form", acNormal, , "ClID=" & Me.CmboSearch.Column(0), acFormEdit, acWindowNormal, "ID=" & Me.CmboSearch.Column(1)
Forms!Client_intake_Form.SetFocus
Exit_CmboSearch_AfterUpdate:
Exit Sub
Err_CmboSearch_AfterUpdate:
Msgbox Err.Description
Resume Exit_CmboSearch_AfterUpdate
End Sub
Code to find the correct person- this doesn't work
Code:
Private Sub loadtab()
'delays loading of information until the user selects the tab
Dim sql As String
Dim sqlOpen As String
Dim rs As Object
Dim db As Database
Set db = CurrentDb
Select Case Me.DetailsTabs.Value
Case Is = Me.DetailsTabs.Pages("persons_Page").PageIndex
sqlOpen = "SELECT tblClients.ClID, tblPersons.Cl_ID, tblpersons.ID, tblPersons.Cl_Lastname, tblPersons.Cl_FirstName, tblPersons.HeadHousehold, " & _
"tblPersons.Cl_Gender, tblPersons.Cl_DOB, tblPersons.Cl_AgeType, tblPersons.Grdn_ID, tblPersons.Cl_Veteran, tblPersons.Ethnic_ID, tblPersons.Race_ID, " & _
"tblPersons.Cl_Employer, tblPersons.Cl_EmploymentStatus, tblPersons.Inactive, tblPersons.Cl_incarcerated, tblPersons.Cl_incarcerationType " & _
"FROM tblClients INNER JOIN tblPersons ON tblClients.ClID = tblPersons.Cl_ID;"
Me.Persons_subform.Form.RecordSource = sqlOpen
Set rs = db.OpenRecordset(sqlOpen)
If Not rs.BOF And rs.EOF Then
rs.FindFirst "[ID] = " & Me.OpenArgs
rs.Bookmark = Me.Bookmark
End If
Me.Persons_subform.Form.Requery
..there are more case options here
End Select
End Sub
Thanks in advance for looking at this.