473,322 Members | 1,425 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,322 software developers and data experts.

Everything deleted using DoCmd.RunSQL

1
Hi, I thought I found a great command in RunSQL, but....

In my Unload event for a form, I added some clean-up code:
Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(Me.ID.Value) And Not IsEmpty(Me.ID.Value) Then
DoCmd.RunSQL "delete * from tblStarDudes where id=" & Me.ID.Value
End If
End Sub

When it reached the delete, a msg popped up to confirm deletion of a number of records equal to everything in my table (1307 rows). I tried to run this as a query, and found that "ID" is not actually a column in my table. (When I correct the column name, it tries to delete the expected 0/1/2/etc. records. I sure don't want to rely on this command, if a mistake could end up in all my data being deleted!)

So...if this query is apparently invalid, can anyone shed some light on why or how it would be trying to delete all my records?

Thanks!
Mar 26 '07 #1
2 3190
Denburt
1,356 Expert 1GB
Are you using Option Explicit in your modules?
Try using Me!ID and you should get an error if the control does not exist.
Mar 26 '07 #2
ADezii
8,834 Expert 8TB
Hi, I thought I found a great command in RunSQL, but....

In my Unload event for a form, I added some clean-up code:
Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(Me.ID.Value) And Not IsEmpty(Me.ID.Value) Then
DoCmd.RunSQL "delete * from tblStarDudes where id=" & Me.ID.Value
End If
End Sub

When it reached the delete, a msg popped up to confirm deletion of a number of records equal to everything in my table (1307 rows). I tried to run this as a query, and found that "ID" is not actually a column in my table. (When I correct the column name, it tries to delete the expected 0/1/2/etc. records. I sure don't want to rely on this command, if a mistake could end up in all my data being deleted!)

So...if this query is apparently invalid, can anyone shed some light on why or how it would be trying to delete all my records?

Thanks!
Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(Me.ID.Value) And Not IsEmpty(Me.ID.Value) Then
If Me![ID] contains data and Me![ID] was initialized? Is this redundant?

__1. IsEmpty returns a Boolean value indicating whether a variable has been initialized and only returns meaningful information for Variants.
__2. I find that it is always a better idea to use the Bang! (not Dot.) when referencing Fields.
__3. I also always find it a good idea to enclose Field Names in brackets ([]).
__4. You should not have to specify the Value Property since it is the Default.
__5. Taking the above items into consideration, try:
Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(Me![ID]) Then
Mar 27 '07 #3

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

Similar topics

3
by: Pathfinder | last post by:
Hi All I am trying to run the below but I receive the following error "runsql action requires an argument consisting of an SQL statment" Dim MySQL$ MySQL$ = "Select * from mytablename"...
7
by: Richard Hollenbeck | last post by:
Help! I don't know why this isn't working: Private Sub Combo9_Change() Dim UsersCourseSelection As String UsersCourseSelection = Me("Combo9").Value Combo13.Visible = True 'the following...
8
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
6
by: David | last post by:
I am trying to insert an employee number into the EmpNbr field in my main table from a form where I add a new employee to my employee table. I was hoping this command would work, but it isn't. ...
2
by: Stu | last post by:
Hi, I've been working on trying to use a combo box to filter my records for a while now, and can't get it to work. Right now, I have SQL code written into IfThen statements on the afterupdate for...
4
by: Regnab | last post by:
I've got a number of 'Lots' of cattle - ie 40A, 372A, W123 etc. The letter in the Lot number indicates where the animal is traceable or not. The animal's Lot number, along with its individual...
2
by: paula | last post by:
I have a front-end access database that uses a sql server back-end to link the tables. When I run the following code, the subform displays #deleted in place of the deleted record. What am I doing...
12
by: jpatchak | last post by:
Hello all, I have an annoying message popping up every time I close a form. Due to performance issues, I am caching data from a linked table on a SQL Server into a temporary local table. The...
2
by: Constantine AI | last post by:
I am wanting to import CSV files into Access, which isn't a problem at the moment the code i have is as follows: Dim strSQL As String Dim CSVTable As String Dim FilePath As String Dim Result As...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.