473,407 Members | 2,546 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,407 software developers and data experts.

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 3996
"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, cboSelectToDelete, on the Form. The RowSource of the
ComboBox is SELECT WorkerID FROM tblWorkers ORDER BY [WorkerID]; and the
default value property is =[cboSelectToDelete].[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!cboSelectToDelete

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.Execute strSQL
"Larry Linson" <bo*****@localhost.not> wrote in message news:<Cw16d.5230$ku4.3570@trnddc01>...
"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, cboSelectToDelete, on the Form. The RowSource of the
ComboBox is SELECT WorkerID FROM tblWorkers ORDER BY [WorkerID]; and the
default value property is =[cboSelectToDelete].[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!cboSelectToDelete

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*********@natpro.com (Roger) wrote:
why do you propose to do
Set db = CurrentDb
db.Execute strSQL

instead of just
currentDb.Execute 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.Execute 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 "#Eliminated".
Thanks
Bernd

"Larry Linson" <bo*****@localhost.not> ha scritto nel messaggio
news:Cw16d.5230$ku4.3570@trnddc01...
"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, cboSelectToDelete, on the Form. The RowSource of the ComboBox is SELECT WorkerID FROM tblWorkers ORDER BY [WorkerID]; and the
default value property is =[cboSelectToDelete].[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!cboSelectToDelete

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
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: ...
3
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...
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...
0
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...
4
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:...
1
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...
4
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...
5
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...
21
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.