SELECT AMFLIBP_MOHRTG.* FROM AMFLIBP_MOHRTG WHERE (((AMFLIBP_MOHRTG.ORDNO)='M776430') AND ((AMFLIBP_MOHRTG.CLDT)=0)) UNION ALL SELECT AMFLIBP_MOROUT.* FROM AMFLIBP_MOROUT WHERE AMFLIBP_MOROUT.ORDNO='M776430' AND AMFLIBP_MOROUT.PRVAL= ORDER BY OPSEQ;
I imagine it's failing at this point as there is no value for PRVAL. An empty control on a form perhaps?
Code:AMFLIBP_MOROUT.PRVAL= ORDER BY OPSEQ
WHERE AMFLIBP_MOROUT.ORDNO='" & [B]someValue[/B] & "' AND AMFLIBP_MOROUT.PRVAL=" & [B]otherValue[/B] & " ORDER BY OSEQ
It's wherever you are getting your criteria from in the WHERE clause. It's like it was ...
Code:WHERE AMFLIBP_MOROUT.ORDNO='" & [B]someValue[/B] & "' AND AMFLIBP_MOROUT.PRVAL=" & [B]otherValue[/B] & " ORDER BY OSEQ
Where are you getting otherValue from?
It's probably Null, so perhaps wrapping that in the Nz() function to force a 0 in there?
"Syntax error (missing operator) in query expression 'AMFLIBP_MOROUT.ORDNO="M794840"
AND AMFLIBP_MOROUT.PRVAL='
According to your earlier post you are getting the result ..
Code:"Syntax error (missing operator) in query expression 'AMFLIBP_MOROUT.ORDNO="M794840" AND AMFLIBP_MOROUT.PRVAL='
You are getting the value "M794840" from somewhere and it is working whereas wherever you are trying to get the other value from is failing to provide an answer.
strSQL1 = strSQL1 & "WHERE AMFLIBP_MOROUT.ORDNO='" & MNbr & "'
AND AMFLIBP_MOROUT.PRVAL=" & PRVAL & " "
So the problem is probably PRVAL, which may need to become nz(PRVAL,0) ...
strSQL1 = strSQL1 & "WHERE AMFLIBP_MOROUT.ORDNO='" & MNbr & "'
AND AMFLIBP_MOROUT.PRVAL=" & NZ(PRVAL,0) & " "
strSQL1 = strSQL1 & "WHERE AMFLIBP_MOROUT.ORDNO='" & MNbr & "'
AND AMFLIBP_MOROUT.PRVAL=" & PRVAL & " "
So the problem is probably PRVAL, which may need to become nz(PRVAL,0) ...
strSQL1 = strSQL1 & "WHERE AMFLIBP_MOROUT.ORDNO='" & MNbr & "'
AND AMFLIBP_MOROUT.PRVAL=" & NZ(PRVAL,0) & " "
You are getting MNbr and CLDT from somewhere and they appear to be all right, it's just PRVAL.
Is it a variable? A control on a form? A column from a table / query?
Dim strSQL1 As String
Dim rst As DAO.Recordset
Dim rst1 As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Operations")
strSQL1 = "SELECT AMFLIBP_MOHRTG.* "
strSQL1 = strSQL1 & "FROM AMFLIBP_MOHRTG "
strSQL1 = strSQL1 & "WHERE (((AMFLIBP_MOHRTG.ORDNO)='" & MNbr & "') AND ((AMFLIBP_MOHRTG.CLDT)=" & CLDT & ")) "
strSQL1 = strSQL1 & "UNION ALL SELECT AMFLIBP_MOROUT.* "
strSQL1 = strSQL1 & "FROM AMFLIBP_MOROUT "
strSQL1 = strSQL1 & "WHERE AMFLIBP_MOROUT.ORDNO='" & MNbr & "' AND AMFLIBP_MOROUT.PRVAL=" & PRVAL & " "
strSQL1 = strSQL1 & "ORDER BY OPSEQ;"
Debug.Print strSQL1
Set rst1 = CurrentDb.OpenRecordset(strSQL1) 'just collect the information of the Operations tables and enter same name in the normal and extra field
rst1.MoveFirst
Do Until rst1.EOF
rst.AddNew
rst!ORDNO = MNbr
rst!CLDT = CLDT
rst!LATDT = LATDT
rst!CORD = MNbr
rst!CCLDT = CLDT
rst!CLATD = LATDT
rst!CASTDT = ASTDT
rst!OP = rst1!OPSEQ
rst!CASTDT = rst1!ASTDT
rst.Update
rst1.MoveNext
Loop
Set rst = Nothing
Sub MotherPacketOP(MNbr As String, LATDT As String, CLDT As String, PRVAL As String, ASTDT As String)
Dim strSQL1 As String
Dim rst As DAO.Recordset
Dim rst1 As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Operations")
strSQL1 = "SELECT AMFLIBP_MOHRTG.* "
strSQL1 = strSQL1 & "FROM AMFLIBP_MOHRTG "
strSQL1 = strSQL1 & "WHERE (((AMFLIBP_MOHRTG.ORDNO)='" & MNbr & "') AND ((AMFLIBP_MOHRTG.CLDT)=" & CLDT & ")) "
strSQL1 = strSQL1 & "UNION ALL SELECT AMFLIBP_MOROUT.* "
strSQL1 = strSQL1 & "FROM AMFLIBP_MOROUT "
strSQL1 = strSQL1 & "WHERE AMFLIBP_MOROUT.ORDNO='" & MNbr & "' AND AMFLIBP_MOROUT.PRVAL= '" & Nz(PRVAL, "") & "' "
strSQL1 = strSQL1 & "ORDER BY OPSEQ;"
Debug.Print strSQL1
Set rst1 = CurrentDb.OpenRecordset(strSQL1) 'just collect the information of the Operations tables and enter same name in the normal and extra field
rst1.MoveFirst
Do Until rst1.EOF
rst.AddNew
rst!ORDNO = MNbr
rst!CLDT = CLDT
rst!LATDT = LATDT
rst!CORD = MNbr
rst!CCLDT = CLDT
rst!CLATD = LATDT
rst!CASTDT = ASTDT
rst!OP = rst1!OPSEQ
rst!CASTDT = rst1!ASTDT
rst.Update
rst1.MoveNext
Loop
Set rst = Nothing
End Sub