Are you doing this in a macro? or are you doing this in VBA code module? I
would use a vba code module.
The query is always going to prompt for the parameter. It has nothing to do
with the structure of the IIF. I'm guessing that the query engine is
basically saying I have a parameter that I don't have a value for and I
(may) need the value. I won't proceed until I know what the value of this
parameter is.
I would probably use vba in the form. SInce I don't know when (which event
or from where ) you are trying to do this I can only post some very generic
UNTESTED AIRCODE as a suggestion. Note this code has no error handling, no
data validation in code, etc.
Dim vValue as Variant
If Forms!formFPMByNum!MACHID="chi-002" Or
Forms!formFPMByNum!MACHID="car-001" Or
Forms!formFPMByNum!MACHID="car-002" Then
'Get the value from a control on a form or ask the user for the value
vValue= Forms!formFPMByNum!SomeValueOnForm
'Or you can use
vValue= InputBox("What EFLH","EFLH",10)
ELSE
vValue= 0
END IF
If IsNumeric(vValue) = True Then
StrSQL = "UPDATE FPM INNER JOIN tblFPMTemp " & _
" ON FPM.MACHID = tblFPMTemp.MACHID " & _
" SET tblFPMTemp.EFLH =" & lngValue & _
" WHERE (((tblFPMTemp.MACHID)=""" & _
Forms]![formFPMByNum]![MACHID] & """"
CurrentDb().Execute StrSQL, dbFailOnError
Else
Msgbox "Invalid EFLH value"
End if
Is it always going to ask because it is a parameter in a query or
because I have the IIF statement worded wrong?
You suggest testing my control in a macro then running the query if
needed. What basic method would you suggest? I'm fairly ignorant of
how to write procedural codes.My thought was to open the form and, in
the "before update event", place code to check the machID control. If
the values where right I'd open a dialog box to enter in EFLH and place
a macro button there to run the update query, close the dialog box and
return to the form. HOW to do that is beyond my knowledge at the
moment.
John said:
The query is always going to ask for the value of [Enter elfh]. I can
see
no way around it as you've designed this query.
UPDATE FPM INNER JOIN tblFPMTemp
ON FPM.MACHID = tblFPMTemp.MACHID
SET tblFPMTemp.EFLH =
IIf(Forms!formFPMByNum!MACHID="chi-002" Or
Forms!formFPMByNum!MACHID="car-001" Or
Forms!formFPMByNum!MACHID="car-002",[enter elfh],0),
FPM.EFLH =IIf(Forms!formFPMByNum!MACHID="chi-002" Or
Forms!formFPMByNum!MACHID="car-001" Or
Forms!formFPMByNum!MACHID="car-002",[enter
elfh],0)
WHERE (((tblFPMTemp.MACHID)=[Forms]![formFPMByNum]![MACHID]));
Perhaps you can test the value of the control in your macro and then run
one
of two queries.
I have the query below opening up in a macro to try and update the hour
meter records on certain equipment. I'm wanting the thing to ask for
the EFLH only when the MachID on the form = one of three possibilties.
The dialog box for EFLH keeps coming up regardless of the MachID, can
anyone see anything obvious that I'm doing wrong?
UPDATE FPM INNER JOIN tblFPMTemp ON FPM.MACHID = tblFPMTemp.MACHID SET
tblFPMTemp.EFLH = IIf(Forms!formFPMByNum!MACHID="chi-002" Or
Forms!formFPMByNum!MACHID="car-001" Or
Forms!formFPMByNum!MACHID="car-002",[enter elfh],0), FPM.EFLH =
IIf(Forms!formFPMByNum!MACHID="chi-002" Or
Forms!formFPMByNum!MACHID="car-001" Or
Forms!formFPMByNum!MACHID="car-002",[enter elfh],0)
WHERE (((tblFPMTemp.MACHID)=[Forms]![formFPMByNum]![MACHID]));