私が現在持っているクエリはある程度機能します。アクセス クエリ デザインで以下のクエリを実行すると、関連する会社 ID を持つすべての従業員が表示されます。Link_Table.FirstName
ただし、VBA では、文字列の最初のレコードのみが表示されますMe.txtbxFirstName = rst!FirstName
。たとえば、値はLink_Table.FirstName
テーブルの最初のレコードだけですか? または、反復できる複数の値を保持できますか?
Public Function DataLookup()
Dim CompDetailSQL As String
Dim rst As DAO.Recordset
CompDetailSQL = "SELECT Companies.CompanyID, Companies.CompanyName,
Companies.AddressNo,
Companies.AddressLine1, Companies.AddressLine2, Companies.AddressLine3,
Companies.AddressPostcode, Companies.AddressCounty,
Companies.Description,
Companies.MainTelephone,
Companies.MainEmail,
Companies.WebAddress,
Link_Table.FirstName
FROM Companies
INNER JOIN Link_Table ON Companies.CompanyID = Link_Table.CompanyID
WHERE Companies.CompanyID = " & Me.lstBoxCompanyName.Value
Debug.Print CompDetailSQL
Set rst = CurrentDb.OpenRecordset(CompDetailSQL, dbOpenSnapshot)
Me.lblDescription.Caption = rst!Description
Me.txtbxAddressLine1.Value = rst!AddressLine1
Me.txtbxAddressLine2.Value = rst!AddressLine2
Me.txtbxAddressLine3.Value = rst!AddressLine3
Me.txtbxAddressPostcode.Value = rst!AddressPostcode
Me.txtbxAddressCounty.Value = rst!AddressCounty
Me.txtbxMainTelephone.Value = rst!MainTelephone
Me.txtbxMainEmail.Value = rst!MainEmail
Me.txtbxMainWeb.Value = rst!WebAddress
Me.txtbxFirstName = rst!FirstName
rst.Close
Set rst = Nothing
End Function