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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing tag and value fails when one is empty 2

Status
Not open for further replies.

glgcag

MIS
Apr 25, 2001
160
US
I am loading a record into my unbound form and putting the values in both the fields and tags of the fields. If the user makes an edit, upon close of the form I run a comparison to see if the ctl.value and ctl.tag don't match, at which point I post the edit.

The problem is that I had a field in which there was a value in both the field and the tag, but then I deleted the value in the field. When I ran my comparison, the empty string (or null?) in the field caused my comparison to fail. Here's the code:

Code:
For each ctl in Me.pgMain.Controls
    If (ctl.ControlType = acTextBox) Then
        If Trim(ctl.Tag) <> Trim(ctl.Value) then
            bEdit = True
        End If
    End If
Next ctl

The problem is that bEdit was false if the tag had text but the value was empty. (Meaning, the user deleted what was in the field.) I changed to Trim(Nz(ctl.Tag, "")) <> Trim(Nz(ctl.Value, "")) and it worked! What am I missing here?

Thanks for the help!
 
I am not sure I get your meaning. If you say:

[tt]a = Null
b = "abc"

a = b 'returns Null, not False.[/tt]

You will often see:
[tt]If Trim(ctl.Tag & " ") <> Trim(ctl.Value & " ") then[/tt]

Which traps zero-length strings and Nulls.
 
Yes, you are correct, albeit I'm looking for "not equal to", as in:

if a = null and b = "abc" doesn't a <> b return True?

What you are saying seems to mean that if a null is involved I won't EVER get a false or true, just null, right?
 
just null, right
Right.
Consider Null as unknown: when something is unknown who can say if it's true or false ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Geez, I'm surprised I haven't gotten myself in major trouble with this.

From now on I'm going to compare all tags and values using your technique of Trim(ctl.tag & " ")!

Thanks guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top