![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| ||||
| ||||
|
|
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 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 |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
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?????? |
|
I want to delete all records where the state equals "MO" for instance |
#6
| |||
| |||
|
|
I'm also puzzled as to why you include the DISTINCTROW clause in the SQL. |
#7
| |||
| |||
|
|
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 |
|
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 |
#8
| |||
| |||
|
|
"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. |
#9
| |||
| |||
|
|
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. |
#10
| |||
| |||
|
|
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). |
![]() |
| Thread Tools | |
| Display Modes | |
| |