Problem fetching record when using lookup fields as criteria.

Problem fetching record when using lookup fields as criteria.

I will appreciate your help in directing me to a solution. I have spent hours with no success.

I have four forms:

frmClients - stores the ClientName and SocialSecurity of clients.

frmProperty - stores the PropertyName, address, phone, etc. of properties.

frmContract - consists of a Lookup field TenantName based on the frmClients, a Lookup field PropertyName based on the frmProperties, and other fields like amount, initialdate, taxrate, deposit, etc.

frmInvoices - consist of a Lookup field UnitName and other fields like TenantName, PaymentMonth, PaymentType, etc.

I am having issues in this last form fetching the TenantName value from the frmContract,

I have the following code in the On User input event of the UnitName at the frmInvoices:

 colContract = frmContract[PropertyName == input.UnitName];
 TenantName = colContract.TenantName;

I have two issues:

The first line will not get a match because of colContract.PropertyName in the frmContract has a different ID that the UnitName in frmProperty.

The second is that colContract.TenantName will return an ID number because is a Lookup field, and the TenantName is a string field. How can I fetch the tenant name in this situation

Error: Variable 'TenantName' is already defined of data type 'STRING' but trying to update 'BIGINT' data type