Hello all,

I have an insert query that looks a bit like this:
Code:
INSERT INTO tableA( ColumnA, ColumnB, ColumnC, ColumnD, ColumnE, ColumnF, ColumnG, ColumnH)

SELECT DISTINCT ValueA, 
     ValueB, 
     "ValueC" AS Expr1, 
     IIf(ValueD Like "US*IM*","UseThisValue",ValueD) AS Expr2,
     ValueE, 
     IIf((IIf(ValueF Like "US*IM*","US Iron Mountain",ValueF))<>ValueD,
          ValueF,Null) AS Expr3, 
     "SREUS-"+[ValueG] AS ValueG, 
     ValueH
FROM TableB
WHERE (((TableB.ValueX)=[ValueZ]));
Okay so essentially, it's got those two IIF statements in there, one of them a nested IIF statement; when I execute the query from the object browser in Microsoft Access, that first statement performs exactly like it's supposed to.

However comma, when I do this in VBA:
Code:
    Set cmd = New ADODB.Command
    With cmd
        Set .ActiveConnection = conn
        .CommandText = "qryImportArchiveBoxes"
        .CommandType = adCmdStoredProc
        .Parameters.Append .CreateParameter("ValueZ", adVarChar,
               adParamInput, 15)
    End With
    cmd.Parameters("ValueZ") = CStr(Z)
    Set rs = New ADODB.Recordset
    rs.Open cmd, , adOpenDynamic, adLockBatchOptimistic
    
    Set rs = Nothing
    Set cmd = Nothing
...that first IIF statement ignores the conditional value and just selects the ValueD instead of the indicated string.

Does anyone have the foggiest clue why this might be happening? I need a seasoned hand on this.

Thanks