473,472 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Completely delete a record inan event

imrosie
222 New Member
Hello,

I have a form that provides a command button for an erase of a image record. However, it only removes the link (image description) to the image, leaving behind full record all the other fields associated with that image. This becomes a problem when a user is searching hrough all records. They get a Null image screen, but the description (auther and date) are still there. How can I completely remove that entire record instead. Here's the code below. thanks in advance

Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("This image will be permanantly removed, Are you sure?", vbYesNo + vbQuestion) = vbYes Then
Me!frmimagesubform.Form![imgPicture].Picture = ""
Me![imageFile] = Null
SysCmd acSysCmdClearStatus
Call Form_Current
End If
End If
End Sub
May 18 '07 #1
13 2065
ADezii
8,834 Recognized Expert Expert
Hello,

I have a form that provides a command button for an erase of a image record. However, it only removes the link (image description) to the image, leaving behind full record all the other fields associated with that image. This becomes a problem when a user is searching hrough all records. They get a Null image screen, but the description (auther and date) are still there. How can I completely remove that entire record instead. Here's the code below. thanks in advance

Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("This image will be permanantly removed, Are you sure?", vbYesNo + vbQuestion) = vbYes Then
Me!frmimagesubform.Form![imgPicture].Picture = ""
Me![imageFile] = Null
SysCmd acSysCmdClearStatus
Call Form_Current
End If
End If
End Sub
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False
  2. Dim strSQL As String
  3.   'DELETES the Current Record
  4.   MySQL = "DELETE * FROM <your table> Where <your table>.<Primary Key> = " & Me![Primary Key Field]
  5.   DoCmd .RunSQL strSQL
  6.   'Move the Record Pointer in some manner
  7. DoCmd.SetWarnings True
May 18 '07 #2
imrosie
222 New Member
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False
  2. Dim strSQL As String
  3.   'DELETES the Current Record
  4.   MySQL = "DELETE * FROM <your table> Where <your table>.<Primary Key> = " & Me![Primary Key Field]
  5.   DoCmd .RunSQL strSQL
  6.   'Move the Record Pointer in some manner
  7. DoCmd.SetWarnings True
Thanks so much for your quick reply. Do I put this code into the event for the command after my code? thanks
May 18 '07 #3
imrosie
222 New Member
Hello,

I tried putting the sql into the event as follows:

Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("The image will be removed permanantly, are you sure?", vbYesNo + vbQuestion) = vbYes Then
'Me!frmimagesubform.Form![imgPicture].Picture = ""
'Me![imageFile] = Null
'SysCmd acSysCmdClearStatus
DoCmd.SetWarnings False
Dim strSQL As String
'DELETES the Current Record
mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
DoCmd .RunSQL strSQL
'Move the Record Pointer IN some manner
DoCmd.SetWarnings True
End If
End If
End Sub

The module tells me it doesn't like the 'Docmd.' please help. thanks
May 18 '07 #4
ADezii
8,834 Recognized Expert Expert
Hello,

I tried putting the sql into the event as follows:

Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("The image will be removed permanantly, are you sure?", vbYesNo + vbQuestion) = vbYes Then
'Me!frmimagesubform.Form![imgPicture].Picture = ""
'Me![imageFile] = Null
'SysCmd acSysCmdClearStatus
DoCmd.SetWarnings False
Dim strSQL As String
'DELETES the Current Record
mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
DoCmd .RunSQL strSQL
'Move the Record Pointer IN some manner
DoCmd.SetWarnings True
End If
End If
End Sub

The module tells me it doesn't like the 'Docmd.' please help. thanks
What Version of Access are you running?
May 18 '07 #5
imrosie
222 New Member
I'm running Access 2002. thanks
May 20 '07 #6
ADezii
8,834 Recognized Expert Expert
Hello,

I tried putting the sql into the event as follows:

Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("The image will be removed permanantly, are you sure?", vbYesNo + vbQuestion) = vbYes Then
'Me!frmimagesubform.Form![imgPicture].Picture = ""
'Me![imageFile] = Null
'SysCmd acSysCmdClearStatus
DoCmd.SetWarnings False
Dim strSQL As String
'DELETES the Current Record
mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
DoCmd .RunSQL strSQL
'Move the Record Pointer IN some manner
DoCmd.SetWarnings True
End If
End If
End Sub

The module tells me it doesn't like the 'Docmd.' please help. thanks
DoCmd .RunSQL strSQL should be:
Expand|Select|Wrap|Line Numbers
  1. DoCmd .RunSQL mysql
May 20 '07 #7
imrosie
222 New Member
Hello,

Thanks for your help, I appreciate. I changed the vb code as you suggested (and recompiled). Now the code tells me that it doesn't understand the line (as follows):

mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]

In fact, the 'mysql' in that line is now covered with a grey bar. May I ask also what is the 'Dim strSQL As String' used for in this scenario? Because once I switched it out and changed that line from:

DoCmd.RunSQL strSQL
TO
DoCmd.RunSQL mysql

I don't see where it going to be used. thanks again.
May 21 '07 #8
imrosie
222 New Member
Hi, just tried another way of putting the complete path to mysql; it give me a problem with the "C:\"Program Files..ect. I've tried "C:"\Program Files, etc. still get the problem that "mysql" variable isn't defined.

Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("This image will be permanantly removed, Are you sure?", vbYesNo + vbQuestion) = vbYes Then
Me!frmimagesubform.Form![imgPicture].Picture = ""
Me![imageFile] = Null
SysCmd acSysCmdClearStatus
DoCmd.SetWarnings False
Dim strSQL As String
'DELETES the Current Record
"C:\"Program Files\MySQL\MySQL Server 4.1\bin\mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
DoCmd.RunSQL mysql
'Move the Record Pointer IN some manner
DoCmd.SetWarnings True
End If
End If
End Sub
Call Form_Current
End If
End If
End Sub

thanks for your time.
May 21 '07 #9
imrosie
222 New Member
I've tried several ways and nothing works...do I need to put the word execute preceding the mysql?

I've just put everything back to the following; it just doesn't like the 'mysql' at beginning of line with ( ="DELETE * FROM imageInventory Where imageInventory.[imageID] = " & Me![imageID]

thanks again.


Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("This image will be permanantly removed, Are you sure?", vbYesNo + vbQuestion) = vbYes Then
Me!frmimagesubform.Form![imgPicture].Picture = ""
Me![imageFile] = Null
SysCmd acSysCmdClearStatus
DoCmd.SetWarnings False
Dim strSQL As String
'DELETES the Current Record
mysql = "DELETE * FROM imageInventory Where imageInventory.[imageID] = " & Me![imageID]
DoCmd.strSQL mysql
'Move the Record Pointer IN some manner
DoCmd.SetWarnings True
End If
End If
End Sub
Call Form_Current
End If
End If
End Sub
May 21 '07 #10
imrosie
222 New Member
I've tried several ways and nothing works...do I need to put the word execute preceding the mysql?

I've just put everything back to the following; it just doesn't like the 'mysql' at beginning of line with ( ="DELETE * FROM imageInventory Where imageInventory.[imageID] = " & Me![imageID]

thanks again.


Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("This image will be permanantly removed, Are you sure?", vbYesNo + vbQuestion) = vbYes Then
Me!frmimagesubform.Form![imgPicture].Picture = ""
Me![imageFile] = Null
SysCmd acSysCmdClearStatus
DoCmd.SetWarnings False
Dim strSQL As String
'DELETES the Current Record
mysql = "DELETE * FROM imageInventory Where imageInventory.[imageID] = " & Me![imageID]
DoCmd.strSQL mysql
'Move the Record Pointer IN some manner
DoCmd.SetWarnings True
End If
End If
End Sub
Call Form_Current
End If
End If
End Sub

In fact, can't I just remove these 3 lines from my code and get a better result once I get the 'mysql' working? thanks again
Me!frmimagesubform.Form![imgPicture].Picture = ""
Me![imageFile] = Null
SysCmd acSysCmdClearStatus
May 21 '07 #11
ADezii
8,834 Recognized Expert Expert
Hi, just tried another way of putting the complete path to mysql; it give me a problem with the "C:\"Program Files..ect. I've tried "C:"\Program Files, etc. still get the problem that "mysql" variable isn't defined.

Private Sub cmdErasePic_Click()
If Not IsNull([imageFile]) Then
If MsgBox("This image will be permanantly removed, Are you sure?", vbYesNo + vbQuestion) = vbYes Then
Me!frmimagesubform.Form![imgPicture].Picture = ""
Me![imageFile] = Null
SysCmd acSysCmdClearStatus
DoCmd.SetWarnings False
Dim strSQL As String
'DELETES the Current Record
"C:\"Program Files\MySQL\MySQL Server 4.1\bin\mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
DoCmd.RunSQL mysql
'Move the Record Pointer IN some manner
DoCmd.SetWarnings True
End If
End If
End Sub
Call Form_Current
End If
End If
End Sub

thanks for your time.
just tried another way of putting the complete path to mysql; it give me a problem with the "C:\"Program Files..ect. I've tried "C:"\Program Files, etc. still get the problem that "mysql" variable isn't defined.
Why are you attempting to set a Path to mysql? it is a String Variable and will contain the SQL String to be executed. Here are your 'Critical' lines of code, do not attempt to modify them in any manner:
Expand|Select|Wrap|Line Numbers
  1. Dim mysql As String       'Declare the Variable
  2.  
  3. 'assign SQL String to the Variable mysql
  4. mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
  5.  
  6. 'Execute the SQL Statement
  7. DoCmd.RunSQL mysql
Double check the following:
  1. Is the Table Name imageInventory?
  2. Are you referring to the proper Field on the Form, namely imageID?
  3. If the response to the above question was Yes, is imageID a Numeric Field? If it is not, then the Syntax has to be changed.
May 21 '07 #12
imrosie
222 New Member
Why are you attempting to set a Path to mysql? it is a String Variable and will contain the SQL String to be executed. Here are your 'Critical' lines of code, do not attempt to modify them in any manner:
Expand|Select|Wrap|Line Numbers
  1. Dim mysql As String       'Declare the Variable
  2.  
  3. 'assign SQL String to the Variable mysql
  4. mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
  5.  
  6. 'Execute the SQL Statement
  7. DoCmd.RunSQL mysql
Double check the following:
  1. Is the Table Name imageInventory?
  2. Are you referring to the proper Field on the Form, namely imageID?
  3. If the response to the above question was Yes, is imageID a Numeric Field? If it is not, then the Syntax has to be changed.

Thanks. Yes the tbl name is imageInventory and the imageID is a numeric field. I was attempting to use the code given me on the first post to this discussion.
Do I need the DoCmd.SetWarnings False and DoCmd.SetWarnings True statements now as suggested in the first post.
May 21 '07 #13
cgrider
19 New Member
Thanks. Yes the tbl name is imageInventory and the imageID is a numeric field. I was attempting to use the code given me on the first post to this discussion.
Do I need the DoCmd.SetWarnings False and DoCmd.SetWarnings True statements now as suggested in the first post.
you need them only if you dont want a confirmation on the deletion of the record in the table which, in most cases, you do not want.

CG
May 21 '07 #14

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

Similar topics

8
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: ...
4
by: Susan Bricker | last post by:
I have a command button on a form that is supposed to Delete the record being displayed. The record is displayed one to a form. The form is not a Pop-Up nor is it Modal. Tracing the btnDelete...
2
by: Mike Moore | last post by:
asp.net app - How do you get Java-side code to communicate with server-side code? I have tried numerous ways and examples, but have been unsuccessful. Therefore, unless I get real lucky and find...
1
by: Woody Splawn | last post by:
I have a datagrid. Through the normal means I highlight a record in the datagrid and press the delete key. I say yes and the record is deleted. However, in this case I need to run some code after...
4
by: drakuu | last post by:
Hello there, I have DataGrid with some records and I would like to edit it right in the datagrid using the built in commands. I can't figure out a way to pass to the SQL query the record ID...
2
by: Iain | last post by:
Hi All I am witing a web app using Delphi developer 2006 (C# app) and I have a datagrid. Excuse the numptyness of the question. I have a datagrid with the ability to Insert, Edit/Update and...
4
by: Phil Stanton | last post by:
Sorry to repost, but am having another look at deleting a record. I have a form (Member) and have removed all the event procedures associated with the Form (OnCurrent, OnDelete, OnActivate etc)...
0
by: David C | last post by:
I have a GridView with a Delete link and wondered where the best place was to check and cancel delete of a row/record that is bound to an SqlDatasource. I can use datasource Deleting event or...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.