473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Delete table records with SQL when field is empty

22
I have tables imported into Access titled: sheet1, sheet2, etc. There are 4 fields in each table-resident, physician, comment and physician_comment. I am trying to write a SQL delete query to allow the user to 1. select a sheet (table) then 2. delete rows in the table where the physician_comment is empty. The code reads as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command28_Click()
  2.    Dim StrSql As String
  3.    Dim tbl As String
  4.    MyValue1 = InputBox("Enter File Number", "MyInputbox")
  5.    MsgBox "Sheet" & MyValue1
  6.    tbl = "Sheet" & MyValue1
  7.    StrSql = "DELETE FROM tbl WHERE tbl.PhysicianComment,"""
  8.    DoCmd.RunSQL StrSql
  9. End Sub
  10.  
  11.  
Mar 25 '12 #1
1 2425
Stewart Ross
2,545 Expert Mod 2GB
You need to include the value of variable tbl in your SQL string. Also, your DELETE statement is missing its 'all records' wildcard (*), and your WHERE clause will not work as it stands.

Assuming that the PhysicianComment field is null when empty (that is, it does not contain any value at all, so it does not evaluate to an empty string) replace line 7 above as follows:

Expand|Select|Wrap|Line Numbers
  1. StrSql = "DELETE * FROM [" & tbl & "] WHERE PhysicianComment IS NULL"
If, as I doubt will be the case, PhysicianComment really is an empty string when there is no value, try:

Expand|Select|Wrap|Line Numbers
  1. StrSql = "DELETE * FROM [" & tbl & "] WHERE PhysicianComment = ''"
I note that your post does not show a consistent name for the field PhysicianComment. In your code it is as shown here, but in your text it is referred to as physician_comment instead. This is a crucial point - SQL statements do not tolerate errors in field or table names.

If in fact your field is named physician_comment then you MUST use that version in your SQL statement. If your field is actually named Physician Comment (with the space as shown) then you need to enclose the field name in square brackets, like this: [Physician Comment]

-Stewart
Mar 25 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jacky Luk | last post by:
Hi, I can't seem to find a way to delete all records of a table. I created my tables in MySQL Query Browser, then fill them up with VC++, but some records were incorrect, And I had to recreate the...
2
by: ms | last post by:
Access 2000: I am trying to delete duplicate records imported to a staging table leaving one of the duplicates to be imported into the live table. A unique record is based on a composite key of 3...
4
by: KT | last post by:
Is there any one click solution that would do the trick? I would like to create a button, so the person who maintains the database can perform clean up work to delete duplicate records which...
3
by: jeff | last post by:
Dear all, i want to delete all records in a table (ms access database) now my method used is not good, i have to loop all record in the datatable and delete it one by one. however, i can't :
8
by: elastreto | last post by:
Hello, I have been trying, so far in vain, to hide the label and text control in a form when the text control is empty/null. I have looked at past postings and tried the code below, however I...
1
by: nico3334 | last post by:
I am trying to delete all records from all tables in Access through VB coding. I would like to do it dynamically in case new tables are added. Here is what I have so far: I have a form with a...
5
kcdoell
by: kcdoell | last post by:
Hello: I am trying to write a code that will delete all records found in my DAO recordset Below is the code I have so far: 'Procdure to give the user the ability to delete all records 'for a...
6
by: Dilip1983 | last post by:
Hi All, I want to delete duplicate records from a large table. There is one index(INDEX_U1) on 4 columns(col1,col2,col3,col4) which is in unusable state. First of all when i tried to rebuild...
5
WyvsEyeView
by: WyvsEyeView | last post by:
Upon clicking Delete to delete the current record on frmTopics, I want several things to happen: 1) Display a custom message rather than Access's standard "You are about to delete n records" one....
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.