Hi,
I am probably real dumb with these codes. I am working on a small project in which one of the most important things to be done is to delete fields from a table. So what i did was to write a SQL query and connect to a form's command button. But this has to only delete fields where the table's primary key matches with what the user enters in a text field on the form. The SQL code i used is
DELETE field1,field2,field3,.....
FROM <TableName>
WHERE field7=<FormName>.<TextboxName>
But there seems to be a problem with the code. Could someone help me with this
Thanks
12 1782
DELETE field1,field2,field3,.....
FROM <TableName>
WHERE field7=<FormName>.<TextboxName>
Try: - DELETE TableName.field, TableName.field2, TableName.field3
-
FROM TableName
-
WHERE (((TableName.field7)=[Forms]![FormName]![TextboxName));
Make sure that the value in the table field, is of the same type that's being matched up in the form field. (number vs number, text vs text) If not, then a Convert function will be needed.
Try: - DELETE TableName.field, TableName.field2, TableName.field3
-
FROM TableName
-
WHERE (((TableName.field7)=[Forms]![FormName]![TextboxName));
Make sure that the value in the table field, is of the same type that's being matched up in the form field. (number vs number, text vs text) If not, then a Convert function will be needed.
Hi,
I did that but the query does not have a regular query icon but it has a " x!" and that is perhaps why the query is not being connected to the form's command button. If run the query seperately it works though!
Thanks
Nope that's correct, different query types will show different icons. The 'x!' is the delete query icon.
How are you running the query in your form? You should be using: - Private Sub YourCommandButtonName_Click()
-
-
DoCmd.OpenQuery [YourDeleteQueryName]
-
-
End Sub
If that works, you should get prompted a warning that you are deleting rows.
If you want to disable the warnings afterwards, use: - Private Sub YourCommandButtonName_Click()
-
-
DoCmd.SetWarnings False
-
DoCmd.OpenQuery [YourDeleteQueryName]
-
DoCmd.SetWarnings True
-
-
End Sub
Nope that's correct, different query types will show different icons. The 'x!' is the delete query icon.
How are you running the query in your form? You should be using: - Private Sub YourCommandButtonName_Click()
-
-
DoCmd.OpenQuery [YourDeleteQueryName]
-
-
End Sub
If that works, you should get prompted a warning that you are deleting rows.
If you want to disable the warnings afterwards, use: - Private Sub YourCommandButtonName_Click()
-
-
DoCmd.SetWarnings False
-
DoCmd.OpenQuery [YourDeleteQueryName]
-
DoCmd.SetWarnings True
-
-
End Sub
Hi,
I get a error message which is "Can't find project or library". is that something to do with references???
Thanks
Please post what code you're using in your command button click event.
Please post what code you're using in your command button click event.
Code in VB - Private Sub Command22_Click()
-
DoCmd.OpenQuery (Nom)
-
End Sub
And the SQL query is . - DELETE [Nominations].[Employee_Id], [Nominations].[Employee_Name], [Nominations].[Team_Leader], [Nominations].[Date_Of_Training], [Nominations].[Training_Name], [Nominations].[Hours_Of_Training], [Nominations].[Venue], [Nominations].[Time], [Nominations].[Trainee_Id]
-
FROM Nominations
-
WHERE [Nominations].[Trainee_Id]=[Forms]![Cancel Nominations]!Text5;
Edit: forgot the quotes around the query name =)
paste this over your form code: - Private Sub Command22_Click()
-
DoCmd.OpenQuery "Nom"
-
End Sub
and paste this over your query code in SQL view -
DELETE [Nominations].[Employee_Id], [Nominations].[Employee_Name], [Nominations].[Team_Leader], [Nominations].[Date_Of_Training], [Nominations].[Training_Name], [Nominations].[Hours_Of_Training], [Nominations].[Venue], [Nominations].[Time], [Nominations].[Trainee_Id]
-
FROM Nominations
-
WHERE ((([Nominations].[Trainee_Id])=[Forms]![Cancel Nominations]![Text5]));
-
Edit: forgot the quotes around the query name =)
paste this over your form code: - Private Sub Command22_Click()
-
DoCmd.OpenQuery "Nom"
-
End Sub
and paste this over your query code in SQL view -
DELETE [Nominations].[Employee_Id], [Nominations].[Employee_Name], [Nominations].[Team_Leader], [Nominations].[Date_Of_Training], [Nominations].[Training_Name], [Nominations].[Hours_Of_Training], [Nominations].[Venue], [Nominations].[Time], [Nominations].[Trainee_Id]
-
FROM Nominations
-
WHERE ((([Nominations].[Trainee_Id])=[Forms]![Cancel Nominations]![Text5]));
-
Hey it works... Thanks a lottttt!!!
Hey it works... Thanks a lottttt!!!
Glad to help =) Have fun!
NeoPa 32,556
Expert Mod 16PB
FYI: DELETE queries delete records rather than fields. Deleting a field would involve changing the design of the table whereas deleting records is simply unloading some of the data.
This means that it is entirely unnecessary to list the fields in the SQL. The following should work for you just as well (This is not intended in any way as criticism MegaLog - Quite the contrary, you've given a fair bit of helpful advice in this thread :)) : - DELETE *
-
FROM Nominations
-
WHERE [Trainee_Id]=[Forms]![Cancel Nominations]![Text5]
FYI: DELETE queries delete records rather than fields. Deleting a field would involve changing the design of the table whereas deleting records is simply unloading some of the data.
This means that it is entirely unnecessary to list the fields in the SQL. The following should work for you just as well (This is not intended in any way as criticism MegaLog - Quite the contrary, you've given a fair bit of helpful advice in this thread :)) : - DELETE *
-
FROM Nominations
-
WHERE [Trainee_Id]=[Forms]![Cancel Nominations]![Text5]
That was going to be my next suggestion if it didnt work.. I only use "Delete *" in my queries. If I delete only certain field data, I use an update query... which I hope isnt what the OP wanted =) I dont take it as criticism, I like the FYI's, usually learn a little fact here and there.
NeoPa 32,556
Expert Mod 16PB
Good to hear it - and keep up the good work - some good stuff recently :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ScottH |
last post by:
I was looking for thw SQL to delete dupes from a table, and came across
this. All who saw it agreed in principle, but I can't quite figure out the
logic. If we are deleting all rows whose rowid...
|
by: patrick.mcdonald |
last post by:
Hello,
Example:
I have 100 rows that all have the field vaule of 'XYZ' I would like to
delete only 10 of those rows.
Is there such a query like "Delete 10 rows from table where table.field...
|
by: Dixie |
last post by:
How do I, in VBA from an access form module, add 5 rows to the top of a
spreadsheet called MySpreadsheet.xls. The worksheet is called MyWorksheet
and there is already data in the first 5 rows. I...
|
by: Christoph |
last post by:
I'm delving into using ADO.NET for the first time. In fact, I've never
done any database work using C# at all so all of this is new to me.
Please bear that in mind if I am asking stupid questions....
|
by: Robert Brown |
last post by:
Hi All.
I have a routine that checks a SQL Table for all records 3 months
prior to a predetermined date, then I insert them into an Archive DB
then delete those records from the original table....
|
by: skennd |
last post by:
Here's my problem in exact replication:
I have used the find duplicate query in Access, and the query
determined the following duplicate values by the following query:
In (SELECT FROM As...
|
by: Manish |
last post by:
The topic is related to MySQL database.
Suppose a table "address" contains the following records
-------------------------------------------------------
| name | address | phone |...
|
by: Hamed |
last post by:
Hello
I have a DataGrid that a is bound to a DataTable. Some of the rows in the
DataTable should not be deleted. How can I prohibit deleting of some
identified rows?
The problem could be...
|
by: MiziaQ |
last post by:
Hey, I'm using the following code to write entries to a data file and then read them in an msflexgrid. I now would like to add code under a delete button to use the table(grid) to delete rows from...
|
by: flexsingh |
last post by:
Hello there,
I have been trying to delete a row in php for a long time now and its getting frustrating, can any see if they could possible help me please.
My first page is
<?php
// this...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |