![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
picky Just in case there's ever a change hat strFieldname might contain blanks, it would be safer to use DoCmd.RunSQL "DELETE DISTINCTROW [tblQBFTemp].* FROM [tblQBFTemp] WHERE [" & strFieldName & "] < " & lngFrom /picky |
|
Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/djsteele Co-author: "Access Solutions", published by Wiley (no e-mails, please!) "Bob Quintal" wrote in message news:Xns9F37C4981A1E0BQuintal (AT) 69 (DOT) 16.185.252... PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in news:u0pl37pvrlq32cas4036qhan81v1svcdiu (AT) 4ax (DOT) com: Hi, I want to delete some rows in a table depending on the contents of a string (which contains the field name in the table). For Instance: DoCmd.RunSQL "DELETE DISTINCTROW [tblQBFTemp].* FROM [tblQBFTemp] WHERE &[strFieldName] < " & lngFrom Obviously &[strFieldName] generates and error and if I use [strFieldName] I will also get an error because strFieldName isn't a field in the table. DoCmd.RunSQL "DELETE DISTINCTROW [tblQBFTemp].* FROM [tblQBFTemp] WHERE " & strFieldName & " < " & lngFrom |
#12
| |||
| |||
|
|
Should have read a little closer! Rather than RunSQL, I find it's better to use the Execute method; CurrentDb.Execute "DELETE * FROM [tblQBFTemp] " & _ "WHERE [" & strFieldName & "] < " & lngFrom, dbFailOnError See what Allen Browne has at http://www.allenbrowne.com/ser-60.html for a discussion of why. Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/djsteele Co-author: "Access Solutions", published by Wiley (no e-mails, please!) |
|
"PW" wrote in message news:er0p371fs16i3ksffss1oo6396htnj76ea (AT) 4ax (DOT) com... On Fri, 5 Aug 2011 17:25:48 -0400, "Douglas J. Steele" NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote: picky Just in case there's ever a change hat strFieldname might contain blanks, it would be safer to use DoCmd.RunSQL "DELETE DISTINCTROW [tblQBFTemp].* FROM [tblQBFTemp] WHERE [" & strFieldName & "] < " & lngFrom /picky lol! No, not picky! Good to know! I like to cover all bases too. -paulw Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/djsteele Co-author: "Access Solutions", published by Wiley (no e-mails, please!) "Bob Quintal" wrote in message news:Xns9F37C4981A1E0BQuintal (AT) 69 (DOT) 16.185.252... PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in news:u0pl37pvrlq32cas4036qhan81v1svcdiu (AT) 4ax (DOT) com: Hi, I want to delete some rows in a table depending on the contents of a string (which contains the field name in the table). For Instance: DoCmd.RunSQL "DELETE DISTINCTROW [tblQBFTemp].* FROM [tblQBFTemp] WHERE &[strFieldName] < " & lngFrom Obviously &[strFieldName] generates and error and if I use [strFieldName] I will also get an error because strFieldName isn't a field in the table. DoCmd.RunSQL "DELETE DISTINCTROW [tblQBFTemp].* FROM [tblQBFTemp] WHERE " & strFieldName & " < " & lngFrom |
#13
| |||
| |||
|
|
I am not sure if I have tried the excecute method! |
#14
| |||
| |||
|
|
PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in news:sdhu37p0ekcn4823fpe9q49tcu5l8u8bel (AT) 4ax (DOT) com: I am not sure if I have tried the excecute method! If you want to get away from DoCmd.RunSQL (and you should), |
|
Google me and SQLRun(), which is intended as a near drop-in replacement for DoCmd.RunSQL, and is based on the Execute method. |
![]() |
| Thread Tools | |
| Display Modes | |
| |