If in side of If Problem

R

Ryan

Hi,
This is what i have in a function, I have an if statement that has multiple
if statement within. I have closed out all if statements with an end if,
within the if as well as closing out the original if.

If rst![A4] Like "*X*" Then
If Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7] = "" Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY7] = 1
End If
If Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8] = "" Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY8] = 1
End If
Else
End If

If i remove the if statements within the if the rest of the code works and
the field gets populated with data, when i bring them back in the code will
not populate the field.

any help would be appreciated.

Ryan
 
D

Dirk Goldgar

Ryan said:
Hi,
This is what i have in a function, I have an if statement that has
multiple
if statement within. I have closed out all if statements with an end if,
within the if as well as closing out the original if.

If rst![A4] Like "*X*" Then
If Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7] = "" Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY7] = 1
End If
If Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8] = "" Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY8] = 1
End If
Else
End If

If i remove the if statements within the if the rest of the code works and
the field gets populated with data, when i bring them back in the code
will
not populate the field.


I see that your If statements are testing DESCRIPTION7 and DESCRIPTION8 to
see if they are equal to "" (a zero-length string). Most likely, those
controls (when blank) are Null, which is *not* the same as "". If you need
to test for Null, you can't do it using the equals (=) operator, because
nothing is ever equal to Null, by definition. So you have to use the IsNull
function instead, which you could do like this:

'------ start of revised code ------
If rst![A4] Like "*X*" Then
If IsNull(Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7]) Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY7] = 1
End If
If IsNull(Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8]) Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY8] = 1
End If
Else
End If
'------ end of revised code ------

Please note that many of the above code statements will have been wrapped
onto multiple lines by the newsreader, and will have to be rejoined into
single lines of code before they will compile.
 
R

Ryan

Thanks Dirk....worked perfectly

Dirk Goldgar said:
Ryan said:
Hi,
This is what i have in a function, I have an if statement that has
multiple
if statement within. I have closed out all if statements with an end if,
within the if as well as closing out the original if.

If rst![A4] Like "*X*" Then
If Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7] = "" Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY7] = 1
End If
If Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8] = "" Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY8] = 1
End If
Else
End If

If i remove the if statements within the if the rest of the code works and
the field gets populated with data, when i bring them back in the code
will
not populate the field.


I see that your If statements are testing DESCRIPTION7 and DESCRIPTION8 to
see if they are equal to "" (a zero-length string). Most likely, those
controls (when blank) are Null, which is *not* the same as "". If you need
to test for Null, you can't do it using the equals (=) operator, because
nothing is ever equal to Null, by definition. So you have to use the IsNull
function instead, which you could do like this:

'------ start of revised code ------
If rst![A4] Like "*X*" Then
If IsNull(Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7]) Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION7] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY7] = 1
End If
If IsNull(Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8]) Then
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![DESCRIPTION8] = "REPLACE CAP"
Forms![PSV Work Order]![INSPECTION DATA].Form![PSV
PRICING1].Form![QTY8] = 1
End If
Else
End If
'------ end of revised code ------

Please note that many of the above code statements will have been wrapped
onto multiple lines by the newsreader, and will have to be rejoined into
single lines of code before they will compile.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top