I have a form that I am trying to automate by using a Pass Through Query. I have the form to the point that the query will run after an order number is entered in the order number field and a button is pushed. I would like to then have that same button use DLookups to populate other fields in the form from the query that it just ran. Below is the code I am trying to use. I keep getting a "data type mismatch" error when I run this code. If I just run the query, I can copy and paste the information into the form and it is accepted. I can't figure out what I am doing wrong that the DLookup isn't working. Any assistance you can provide would be greatly appreciated.
CurrentDb.QueryDefs("DB2 QUERY").SQL = "SELECT ORNO, CAST(ODAT AS DATE) AS ODAT, STRIP(C.NAME) AS CUST_NAME FROM PROD.TDSLS040100 A JOIN PROD.BAAN_CUST_CONV B ON A.CUNO = B.CUNO JOIN PROD.CUSTOMER C ON B.CCMF = C.CUST_NUM WHERE ORNO = " & [Forms]![DB2 Form]!ORNO
Me.CUSTOMER_NAME = DLookup("[CUST_NAME]", "[DB2 QUERY]", "[ORNO] = '" & Me.[ORNO] & "'")
CurrentDb.QueryDefs("DB2 QUERY").SQL = "SELECT ORNO, CAST(ODAT AS DATE) AS ODAT, STRIP(C.NAME) AS CUST_NAME FROM PROD.TDSLS040100 A JOIN PROD.BAAN_CUST_CONV B ON A.CUNO = B.CUNO JOIN PROD.CUSTOMER C ON B.CCMF = C.CUST_NUM WHERE ORNO = " & [Forms]![DB2 Form]!ORNO
Me.CUSTOMER_NAME = DLookup("[CUST_NAME]", "[DB2 QUERY]", "[ORNO] = '" & Me.[ORNO] & "'")