if statement

  • Thread starter Thread starter mju
  • Start date Start date
M

mju

I need serious help. I am new to Access. I am trying to write up an if
statement.

I have a query and a report setup. What I am trying to do is whenever a
report is ran or data is enter, if ClientPrintDoc = 0 then Jobprice should be
=0
I tried putting the formula in the query view criteria section but I got an
error stating the following:
You cannot specify criteria for the (*)
This is my formula:
=IIf("ClientShipDocs"="0","JobPrice"="0")
Is this formula actually correct? Do I need a macro for this? If yes, how
do I proceed?

Thanks a lot!!
 
You should be entering this information into a form based on the query... in
which case, see the AfterUpdate event of your ClientPrintDoc field, and you
can put the If statement there (after this control updates, we'll set the
JobPrice control accordingly).

Private Sub ClientShipDocs_AfterUpdate()
If Me.ClientShipDocs = 0 Then
Me.JobPrice = 0
End If
End Sub

This assumes that the names of the controls are ClientShipDocs and JobPrice.



Another way to do this would be on the BeforeUpdate of the form detail,
rather than the control.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.ClientShipDocs = 0 Then
Me.JobPrice = 0
End If
End Sub


If ClientShipDocs and JobPrice are fields rather than controls, you can
refer to them using Me![fieldname]

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me![ClientShipDocs] = 0 Then
Me![JobPrice] = 0
End If
End Sub



The Iif (immediate If) function is handled a little bit differently, but you
should be able to use it here. This example would set the value of JobPrice
to 0 if ClientShipDocs is 0, or leave it where it is if not.

Me![JobPrice] = Iif(Me![ClientShipDocs] = 0, 0, Me![JobPrice])



A bit confusing at first, but you'll get the hang of it :-)

good luck!
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
also posted in microsoft.public.access.macros newsgroup, under Subject: If
statements.

please don't multi-post. for more information, see
http://home.att.net/~california.db/tips.html#aTip10.

also, it's a good idea to try to post to a newsgroup that most closely
matches the subject of your question. since your question is about a query,
the best place to start would probably have been newsgroup
microsoft.public.access.queries.

hth
 
Back
Top