The query i have at the moment works to an extent. Running the query below in access query design will display all the employees with a relevant company ID. However with VBA it will only display the first record in Link_Table.FirstName
in the string Me.txtbxFirstName = rst!FirstName
. Will the value of for instance, Link_Table.FirstName
only ever the first record in the table? Or can it hold multiples values which can then be iterated through?
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