Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't figure out how Access is evaluating If statement

Status
Not open for further replies.

hurtsmyhead

Technical User
Jun 3, 2010
8
Hi All,

First I'll set up the situation. I've got a form with three fields, and the first two determine what is written to the third:

InclDriver: a True/False check box.
DrvPartNum: a text box that data is manually entered into, if there is data.
HidDriver: Text, or text plus the contents of DrvPartNum, is written to this field, depending on whether or not DrvPartNum has any data.

This is the code:

If [InclDriver] = True And [DrvPartNum] <> "" Then
HidDriver = "<li>Driver side airbag - Part #" & Me.DrvPartNum.Value & "</li>"
ElseIf [InclDriver] = True And [DrvPartNum] = "" Then
HidDriver = "<li>Driver side airbag</li>"
Else
HidDriver = "It's not working"
End If


If InclDriver is true (checked) and DrvPartNum is not empty, write a text string and the contents of DrvPartNum to the HidDriver field. If InclDriver is true but DrvPartNum is empty, just write a text string. If any other condition exists, write nothing, or for the time being as I test this, write "It's not working".

The first If statement works fine. The ElseIf statement is not working--when InclDriver is true and DrvPartNum is empty Access is not evaluating the statement as true.

I tried it using Null instead of an empty string value but that didn't work at all. The field in the table is set to Allow Zero Length.

What the heck am I missing? I know this will take one of you experienced folks about 15 seconds. I work nights so I'm going to bed right now (this is late even for me), don't be surprised if you don't see my profuse thanks for another eight or nine hours.

Mark
 
when a text box is empty its value is usually null not an empty string

the best test is this
if trim([someTextBox] & " ") = "" then


The above will catch an empty string (""), a space " ", spaces " ", and null
 
You did it again, MajP, thanks a million. I worked on this for hours with no luck.

I wasn't familiar with the Trim function prior to your post, and I always try to learn from the fixes people give me. So, if I'm reading this right, your if statement is saying, if the trimmed contents of a field concatenated with a space equals "", the condition is true. I don't understand what the addition of the & "" does in the expression, though. Trim would just remove that space anyway, wouldn't it?

Mark
 
I don't understand what the addition of the & "" does in the expression
It makes the expression not null.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Got it. Or, it ensures the expression not null even if the value of [someTextBox] is null(?).

Thanks!

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top