I have three tables
tblCustomers -lists customer info
Fields: ID, Name
tblIncrements - defines increments
Fields: ID, IncrementName, IncrementDetails
tblIncrementHistory - keeps track of which increment the customers is and was assigned to, the customers can only be assigned to one increment, but I have to keep track of their past history. The way I know their current history is it is the most recent assigned increment.
Fields: ID, CustomerID (relationship), IncrementID (relationship), ChangeDate
Now, on my Customer form, I want to query the increment name of the increment they are currently assigned to and list that in a txt box. Here is the query I attempted to write, which seems to work okay when I do it in SQL as a test query and change the forms Customer ID to "2":
SELECT TOP 1 [tblIncrements].[IncrementName]
FROM tblIncrements, tblIncrementHistory
WHERE tblIncrementHistory.CustomerID=2 And tblIncrementHistory.IncrementID=tblIncrements.ID
ORDER BY [tblIncrementHistory].[ChangeDate] DESC;
I am not sure how to pass the form's current Customers.ID variable into the SQL query, and think that is why I am having a problem. However, when I attempted to use this code in the text box with 2, I get #Name? in the text box, so I am really confused.
Your help would be greatly appreciated.
Thank you