dbTalk Databases Forums  

How do I disregard text fields that are blank in a query result?

comp.databases.ms-access comp.databases.ms-access


Discuss How do I disregard text fields that are blank in a query result? in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
PW
 
Posts: n/a

Default How do I disregard text fields that are blank in a query result? - 09-02-2011 , 12:34 AM






I want to delete all records where the state equals "MO" for instance
but yet I am getting states that people have left out. The field in
the database is a text field.

This is the line of code:

DoCmd.RunSQL "DELETE DISTINCTROW [tblQBFTemp].* FROM [tblQBFTemp]
WHERE " & [strFieldName] & " <> '" & strText & "'"
End If

In debug, strText = "MO" or whatever and the field "strFieldName" is a
text field in the database

I get lots of records in the table where the field contains "MO" but
yet I also get blank entries for that field.

What am I doing wrong this time :-)

-paulw

Reply With Quote
  #2  
Old   
Rob Parker
 
Posts: n/a

Default Re: How do I disregard text fields that are blank in a query result? - 09-02-2011 , 01:09 AM






The SQL you have will delete all records where the state is NOT equal to
"MO" (for example), and this will include all records where strFieldName is
null, since that also meets the criterion you've set. Change the condition
from <> to = to delete records which match the string in strText.

I'm also puzzled as to why you include the DISTINCTROW clause in the SQL.
And, for simplicity, you don't need the table name to qualify the *. The
following should do what you want:
DoCmd.RunSQL "DELETE * FROM [tblQBFTemp]
WHERE " & [strFieldName] & " = '" & strText & "'"

Rob


"PW" <emailaddyinsig (AT) ifIremember (DOT) com> wrote

Quote:
I want to delete all records where the state equals "MO" for instance
but yet I am getting states that people have left out. The field in
the database is a text field.

This is the line of code:

DoCmd.RunSQL "DELETE DISTINCTROW [tblQBFTemp].* FROM [tblQBFTemp]
WHERE " & [strFieldName] & " <> '" & strText & "'"
End If

In debug, strText = "MO" or whatever and the field "strFieldName" is a
text field in the database

I get lots of records in the table where the field contains "MO" but
yet I also get blank entries for that field.

What am I doing wrong this time :-)

-paulw

Reply With Quote
  #3  
Old   
PW
 
Posts: n/a

Default Re: How do I disregard text fields that are blank in a query result? - 09-02-2011 , 11:35 AM



On Fri, 2 Sep 2011 16:09:00 +1000, "Rob Parker"
<NOSPAMrobpparker (AT) optusnet (DOT) com.au.FORME> wrote:

Quote:
The SQL you have will delete all records where the state is NOT equal to
"MO" (for example), and this will include all records where strFieldName is
null, since that also meets the criterion you've set. Change the condition
from <> to = to delete records which match the string in strText.

I *want* to delete all records that are not equal to what state the
user picked. That was on purpose. If the user selected "MO", why
would I want to delete those records??????

Quote:
I'm also puzzled as to why you include the DISTINCTROW clause in the SQL.
Something I probably found in a book years ago!

Quote:
And, for simplicity, you don't need the table name to qualify the *. The
following should do what you want:
DoCmd.RunSQL "DELETE * FROM [tblQBFTemp]
WHERE " & [strFieldName] & " = '" & strText & "'"

Rob

Simplicity is good!

I am still getting records where the state field is blank. Which was
the subject of this post.


Quote:
"PW" <emailaddyinsig (AT) ifIremember (DOT) com> wrote in message
news:llp067tgh8k29d37vdjumlj98v82qeg6j1 (AT) 4ax (DOT) com...
I want to delete all records where the state equals "MO" for instance
but yet I am getting states that people have left out. The field in
the database is a text field.

This is the line of code:

DoCmd.RunSQL "DELETE DISTINCTROW [tblQBFTemp].* FROM [tblQBFTemp]
WHERE " & [strFieldName] & " <> '" & strText & "'"
End If

In debug, strText = "MO" or whatever and the field "strFieldName" is a
text field in the database

I get lots of records in the table where the field contains "MO" but
yet I also get blank entries for that field.

What am I doing wrong this time :-)

-paulw

Reply With Quote
  #4  
Old   
PW
 
Posts: n/a

Default Re: How do I disregard text fields that are blank in a query result? - 09-02-2011 , 11:41 AM



Doing an additional delete where the field is null took care of the
problem.

DoCmd.RunSQL "DELETE * FROM [tblQBFTemp] WHERE IsNull(" &
[strFieldName] & ")"


Thanks

Reply With Quote
  #5  
Old   
Bob Barrows
 
Posts: n/a

Default Re: How do I disregard text fields that are blank in a query result? - 09-02-2011 , 01:06 PM



PW wrote:
Quote:
On Fri, 2 Sep 2011 16:09:00 +1000, "Rob Parker"
NOSPAMrobpparker (AT) optusnet (DOT) com.au.FORME> wrote:

The SQL you have will delete all records where the state is NOT
equal to "MO" (for example), and this will include all records where
strFieldName is null, since that also meets the criterion you've
set. Change the condition from <> to = to delete records which
match the string in strText.


I *want* to delete all records that are not equal to what state the
user picked. That was on purpose. If the user selected "MO", why
would I want to delete those records??????
Errrr .... Because of what you said here :-) :
Quote:
I want to delete all records where the state equals "MO" for
instance
DoCmd.RunSQL "DELETE * FROM [tblQBFTemp]
WHERE Nz(" & [strFieldName] & ",'" & _
strText & "') <> '" & strText & "'"

Untested. You need to set your code up so you can inspect the result of the
concatenation to verify that it is a valid sql statement when debugging. The
key to this is assigning the result of the concatenation to a variable:

dim sql as string
sql="DELETE * FROM [tblQBFTemp] " & _
WHERE Nz(" & [strFieldName] & ",'" & _
strText & "') <> '" & strText & "'"
debug.print sql
DoCmd.RunSQL sql

Reply With Quote
  #6  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: How do I disregard text fields that are blank in a query result? - 09-03-2011 , 03:36 PM



"Rob Parker" <NOSPAMrobpparker (AT) optusnet (DOT) com.au.FORME> wrote in
news:4e607305$0$13394$afc38c87 (AT) news (DOT) optusnet.com.au:

Quote:
I'm also puzzled as to why you include the DISTINCTROW clause in
the SQL.
....since DISTINCTROW has no effect whatsoever on any SQL statement
that has only one table in the FROM clause.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #7  
Old   
PW
 
Posts: n/a

Default Re: How do I disregard text fields that are blank in a query result? - 09-03-2011 , 04:55 PM



On Fri, 2 Sep 2011 14:06:08 -0400, "Bob Barrows"
<reb01501 (AT) NOSPAMyahoo (DOT) com> wrote:

Quote:
PW wrote:
On Fri, 2 Sep 2011 16:09:00 +1000, "Rob Parker"
NOSPAMrobpparker (AT) optusnet (DOT) com.au.FORME> wrote:

The SQL you have will delete all records where the state is NOT
equal to "MO" (for example), and this will include all records where
strFieldName is null, since that also meets the criterion you've
set. Change the condition from <> to = to delete records which
match the string in strText.


I *want* to delete all records that are not equal to what state the
user picked. That was on purpose. If the user selected "MO", why
would I want to delete those records??????

Errrr .... Because of what you said here :-) :

I want to delete all records where the state equals "MO" for
instance
Gosh Darnit! The opposite of I wanted to say! Sorry about that!

Quote:
DoCmd.RunSQL "DELETE * FROM [tblQBFTemp]
WHERE Nz(" & [strFieldName] & ",'" & _
strText & "') <> '" & strText & "'"

Untested. You need to set your code up so you can inspect the result of the
concatenation to verify that it is a valid sql statement when debugging. The
key to this is assigning the result of the concatenation to a variable:

dim sql as string
sql="DELETE * FROM [tblQBFTemp] " & _
WHERE Nz(" & [strFieldName] & ",'" & _
strText & "') <> '" & strText & "'"
debug.print sql
DoCmd.RunSQL sql


Thanks Bob. What Rob suggested seems to be working so far.

-paul

Reply With Quote
  #8  
Old   
PW
 
Posts: n/a

Default Re: How do I disregard text fields that are blank in a query result? - 09-03-2011 , 04:57 PM



On Sat, 3 Sep 2011 20:36:15 +0000 (UTC), "David-W-Fenton"
<NoEmail (AT) SeeSignature (DOT) invalid> wrote:

Quote:
"Rob Parker" <NOSPAMrobpparker (AT) optusnet (DOT) com.au.FORME> wrote in
news:4e607305$0$13394$afc38c87 (AT) news (DOT) optusnet.com.au:

I'm also puzzled as to why you include the DISTINCTROW clause in
the SQL.

...since DISTINCTROW has no effect whatsoever on any SQL statement
that has only one table in the FROM clause.

Thanks for setting me straight David. I must have somehow gotten that
from some book and I wasn't aware of why they were using it.

Reply With Quote
  #9  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: How do I disregard text fields that are blank in a query result? - 09-07-2011 , 06:39 PM



PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in
news:sk8567t78hdrgahnh6kglri9fn7vkv8qkl (AT) 4ax (DOT) com:

Quote:
On Sat, 3 Sep 2011 20:36:15 +0000 (UTC), "David-W-Fenton"
NoEmail (AT) SeeSignature (DOT) invalid> wrote:

"Rob Parker" <NOSPAMrobpparker (AT) optusnet (DOT) com.au.FORME> wrote in
news:4e607305$0$13394$afc38c87 (AT) news (DOT) optusnet.com.au:

I'm also puzzled as to why you include the DISTINCTROW clause in
the SQL.

...since DISTINCTROW has no effect whatsoever on any SQL statement
that has only one table in the FROM clause.

Thanks for setting me straight David. I must have somehow gotten
that from some book and I wasn't aware of why they were using it.
Or, the SQL dates back to Access 2 or before, which defaulted to
DISTINCTROW in all queries (unless you turned it off).

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #10  
Old   
PW
 
Posts: n/a

Default Re: How do I disregard text fields that are blank in a query result? - 09-20-2011 , 12:56 PM



On Wed, 7 Sep 2011 23:39:18 +0000 (UTC), "David-W-Fenton"
<NoEmail (AT) SeeSignature (DOT) invalid> wrote:

Quote:
PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in
news:sk8567t78hdrgahnh6kglri9fn7vkv8qkl (AT) 4ax (DOT) com:

On Sat, 3 Sep 2011 20:36:15 +0000 (UTC), "David-W-Fenton"
NoEmail (AT) SeeSignature (DOT) invalid> wrote:

"Rob Parker" <NOSPAMrobpparker (AT) optusnet (DOT) com.au.FORME> wrote in
news:4e607305$0$13394$afc38c87 (AT) news (DOT) optusnet.com.au:

I'm also puzzled as to why you include the DISTINCTROW clause in
the SQL.

...since DISTINCTROW has no effect whatsoever on any SQL statement
that has only one table in the FROM clause.

Thanks for setting me straight David. I must have somehow gotten
that from some book and I wasn't aware of why they were using it.

Or, the SQL dates back to Access 2 or before, which defaulted to
DISTINCTROW in all queries (unless you turned it off).

That must be the reason. Not that I have been using Access since
before Access 97 (Is that 2?), but maybe the authors of the books I
have still use it.

Thanks

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.