This is perfect. It does exactly what I need it to do. However, I have one more question. After I update the query definitions and run the query, I want to use a dlookup to enter the data from that query into my form. I keep getting an error message stating that the fields are not updateable. For some reason, I think it is trying to update the query instead of the form. Here is the code that I have:
CurrentDb.QueryDefs("DB2 QUERY").SQL = "SELECT ORNO, ODAT, C.NAME AS CUST_NAME FROM PROD.TDL040100 A JOIN PROD.CUST_CONV B ON A.CUNO = B.CUNO JOIN PROD.CUSTOMER C ON B.CCMF = C.CUST_NUM WHERE ORNO = " & [Forms]![DB2 Form]!ORNO
DoCmd.OpenQuery "DB2 Query", acViewNormal, acEdit
[Forms]![DB2 Form]!ODAT = DLookup("[ODAT]", "[DB2 Query]", "[ORNO] = '" & Me.[ORNO] & "'")
Can you tell me what I'm doing wrong?