473,770 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete record commandbutton

Hi,
I would like to delete a record (with commandbutton) of a table associated
to a combobox, when I select a certain value in the combobox (the value I
select is associated with the record that I want to delete.
For example:
I have a form associated to a table, which has only one field (PatientN°),
and a combobox (within the form) that contains the list of values
(PatientN°) contained in the table. Now I would like to select a value in
the combobox and then click on a button that deletes the selected value.
How can I implement such a button?
Thanks
Nov 13 '05 #1
6 4025
"Bernd Smits" wrote
I would like to delete a record (with commandbutton) of a table associated to a combobox, when I select a certain value in the combobox (the value I
select is associated with the record that I want to delete.
For example: I have a form associated to a table,
which has only one field (PatientN°),
and a combobox (within the form) that
contains the list of values (PatientN°)
contained in the table. Now I would like
to select a value in the combobox and
then click on a button that deletes the
selected value.
How can I implement such a button?
Thanks


Here's a sample:

tblWorkers has Records identified by Field WorkerID

Created an unbound Form (the RecordSource of the Form is empty), frmDelRec,
and placed a Combo Box, cboSelectToDele te, on the Form. The RowSource of the
ComboBox is SELECT WorkerID FROM tblWorkers ORDER BY [WorkerID]; and the
default value property is =[cboSelectToDele te].[ItemData](0) so that the
first item in the list shows when the user hasn't selected anything. Added a
CommandButton, cmdDelete, to the Form. In the Click event of cmdDelete, I
put the following code:

Dim strSQL As String
Dim db As DAO.Database

strSQL = "DELETE * FROM tblWorkers WHERE [WorkerID] = " &
Me!cboSelectToD elete

Set db = CurrentDb
db.Execute strSQL

This works for me.

Good luck with your project.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #2
Larry

why do you propose to do
Set db = CurrentDb
db.Execute strSQL

instead of just
currentDb.Execu te strSQL
"Larry Linson" <bo*****@localh ost.not> wrote in message news:<Cw16d.523 0$ku4.3570@trnd dc01>...
"Bernd Smits" wrote
> I would like to delete a record (with commandbutton) of a table

associated
to a combobox, when I select a certain value in the combobox (the value I
select is associated with the record that I want to delete.
For example:

> I have a form associated to a table,
> which has only one field (PatientN°),
> and a combobox (within the form) that
> contains the list of values (PatientN°)
> contained in the table. Now I would like
> to select a value in the combobox and
> then click on a button that deletes the
> selected value.
> How can I implement such a button?
> Thanks


Here's a sample:

tblWorkers has Records identified by Field WorkerID

Created an unbound Form (the RecordSource of the Form is empty), frmDelRec,
and placed a Combo Box, cboSelectToDele te, on the Form. The RowSource of the
ComboBox is SELECT WorkerID FROM tblWorkers ORDER BY [WorkerID]; and the
default value property is =[cboSelectToDele te].[ItemData](0) so that the
first item in the list shows when the user hasn't selected anything. Added a
CommandButton, cmdDelete, to the Form. In the Click event of cmdDelete, I
put the following code:

Dim strSQL As String
Dim db As DAO.Database

strSQL = "DELETE * FROM tblWorkers WHERE [WorkerID] = " &
Me!cboSelectToD elete

Set db = CurrentDb
db.Execute strSQL

This works for me.

Good luck with your project.

Larry Linson
Microsoft Access MVP

Nov 13 '05 #3
le*********@nat pro.com (Roger) wrote:
why do you propose to do
Set db = CurrentDb
db.Execute strSQL

instead of just
currentDb.Execu te strSQL


It's good practice/laziness (on my part at least ;-)). If you have many
operations to complete using the current db then it's easier and quicker to
declare "db" up front and then type "db." than typing "currentDb. " every
time.

Regards,
Keith.
Nov 13 '05 #4
Roger wrote:
why do you propose to do
Set db = CurrentDb
db.Execute strSQL

instead of just
currentDb.Execu te strSQL


In A97, or possibly an earlier version, I seem to recall reading on this
group there was some kind of issue with memory which made it adviseable
to do it Larry's way and include:

Set db = Nothing

at the procedure's exit point.

I don't know if that's still an issue in A2K or later, but I still do it
this way, myself.

--
Tim - http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #5
I've done what you proposed to do, but now everytime I click on the "delete"
button, the selected record will be removed from the table but in the
combobox, in place of the the selected value (to delete) there is written
#Canceled or #Eliminated but only when I reboot the form #Eliminated and the
value are canceled.
Why does this happen? I would that when I click on the button automaticly
the value in the combobox is canceled, without the writing "#Eliminate d".
Thanks
Bernd

"Larry Linson" <bo*****@localh ost.not> ha scritto nel messaggio
news:Cw16d.5230 $ku4.3570@trndd c01...
"Bernd Smits" wrote
> I would like to delete a record (with commandbutton) of a table associated
to a combobox, when I select a certain value in the combobox (the value I select is associated with the record that I want to delete.
For example:

> I have a form associated to a table,
> which has only one field (PatientN°),
> and a combobox (within the form) that
> contains the list of values (PatientN°)
> contained in the table. Now I would like
> to select a value in the combobox and
> then click on a button that deletes the
> selected value.
> How can I implement such a button?
> Thanks


Here's a sample:

tblWorkers has Records identified by Field WorkerID

Created an unbound Form (the RecordSource of the Form is empty),

frmDelRec, and placed a Combo Box, cboSelectToDele te, on the Form. The RowSource of the ComboBox is SELECT WorkerID FROM tblWorkers ORDER BY [WorkerID]; and the
default value property is =[cboSelectToDele te].[ItemData](0) so that the
first item in the list shows when the user hasn't selected anything. Added a CommandButton, cmdDelete, to the Form. In the Click event of cmdDelete, I
put the following code:

Dim strSQL As String
Dim db As DAO.Database

strSQL = "DELETE * FROM tblWorkers WHERE [WorkerID] = " &
Me!cboSelectToD elete

Set db = CurrentDb
db.Execute strSQL

This works for me.

Good luck with your project.

Larry Linson
Microsoft Access MVP

Nov 13 '05 #6
You need the combo box to get the new records once more. After deleting
the record from the table write:

me.theComboBox. requery

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4066
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: DoCmd.SetWarnings False DoCmd.RunCommand acCmdDeleteRecord DoCmd.SetWarnings True End If ExitHere: Me!SubName.SetFocus
3
3974
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to delete a record in this subform. When I switched modal off and tried to delete a record from the list, I deleted a record on another form (below the popup form).
4
7850
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 event routine shows that AllowDeletions is TRUE. When the Delete button is clicked (without TRACE ON), I get a 'beep', the recordselector (vertical bar on left of form) gets dark in color, but the record is not deleted. Also, there is no error...
0
263
by: kar3n.chandra | last post by:
Hey, i have a c# program opening and creating powerpoint slides and i created a commandbutton on the slide. the problem i'm having is changing the caption of the button. i've placed the code below and the only error is objValue.Caption="Values". when i run the program, the powerpoint crashes at that command.
4
2906
by: Jamey Shuemaker | last post by:
Howdy, Saw a couple threads from the past few years on this topic, but didn't really find any solutions. Here's one I found: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/f6ccff0186d12566/ That fella wanted to do pretty well the same thing I did (use a command button to move between records in a form). Moving from record to record
1
2817
by: neelesh kumar | last post by:
i have 4 optionbuttons in my form. if i select 1st optionbutton traineeans.value=1,2ndbutton traineeans.value=2...like that.If he didnt select anyone traoneeans.value=0. one commandbutton is there named previous unaswered,and other command button is next. if i click that button previousunanswwered i want to go to previous record where traineee ans.value=0. DoCmd.GoToRecord , , acprevious is going to the previous record.but i want to go...
4
2586
by: Craggy | last post by:
Hi, I am trying to pop up a yes/no message box so that a user can delete a record in a continuous form. The default delete message is a bit sloppy because it seems to move the continuous form to the position of the record u want to delete. If you then choose to not to delete the record it looks to a user as if it has deleted every record before the one you chose not to delete. To get around this I made a yes/no msgbox pop up and only after...
5
3944
by: sh26 | last post by:
I can Add and Delete (A, CName, MX and TXT) Dns records on the Dns Server using C# code. The problem I am having is if someone manaully creates a TXT record on the Dns Server, I cannot delete that particular record using the same C# code. Here is what I am using to delete the records: public void DeleteRecord(string domain, string recordName, string recordType, string recordData) { try { ...
21
7162
by: postman | last post by:
I have a subform which is bound to a query which will display records using an ID# supplied from a listbox in the parent form. That same subform is also used to create new records using the following code in a "New Record" commandbutton: DoCmd.GoToRecord , , acNewRec Both functions work fine. However, if I have a selected record displayed, and I click the "New Record" button, it does not move to a new record. It just stays on the...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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 we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.