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
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
- DoCmd.SetWarnings False
-
Dim strSQL As String
-
'DELETES the Current Record
-
MySQL = "DELETE * FROM <your table> Where <your table>.<Primary Key> = " & Me![Primary Key Field]
-
DoCmd .RunSQL strSQL
-
'Move the Record Pointer in some manner
-
DoCmd.SetWarnings True
- DoCmd.SetWarnings False
-
Dim strSQL As String
-
'DELETES the Current Record
-
MySQL = "DELETE * FROM <your table> Where <your table>.<Primary Key> = " & Me![Primary Key Field]
-
DoCmd .RunSQL strSQL
-
'Move the Record Pointer in some manner
-
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
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
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?
I'm running Access 2002. thanks
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:
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.
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.
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
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
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: - Dim mysql As String 'Declare the Variable
-
-
'assign SQL String to the Variable mysql
-
mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
-
-
'Execute the SQL Statement
-
DoCmd.RunSQL mysql
Double check the following:- Is the Table Name imageInventory?
- Are you referring to the proper Field on the Form, namely imageID?
- 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.
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: - Dim mysql As String 'Declare the Variable
-
-
'assign SQL String to the Variable mysql
-
mysql = "DELETE * FROM imageInventory Where imageInventory.imageID = " & Me![imageID]
-
-
'Execute the SQL Statement
-
DoCmd.RunSQL mysql
Double check the following:- Is the Table Name imageInventory?
- Are you referring to the proper Field on the Form, namely imageID?
- 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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |