Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / September 2004

Tip: Looking for answers? Try searching our database.

Delete record commandbutton

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bernd Smits - 27 Sep 2004 23:38 GMT
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
Larry  Linson - 28 Sep 2004 00:39 GMT
> 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?),
[quoted text clipped - 6 lines]
> 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
Roger - 28 Sep 2004 15:33 GMT
Larry

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

instead of just
     currentDb.Execute strSQL

>  > I would like to delete a record (with commandbutton) of a table
>  associated
[quoted text clipped - 40 lines]
>   Larry Linson
>   Microsoft Access MVP
Keith Wilby - 28 Sep 2004 16:31 GMT
> 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.
Tim Marshall - 28 Sep 2004 16:44 GMT
> 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.

Signature

Tim - http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto

Bernd Smits - 30 Sep 2004 15:27 GMT
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" <bouncer@localhost.not> ha scritto nel messaggio
news:Cw16d.5230$ku4.3570@trnddc01...

>  > I would like to delete a record (with commandbutton) of a table
> associated
[quoted text clipped - 40 lines]
>   Larry Linson
>   Microsoft Access MVP
Ron Devonish - 30 Sep 2004 19:00 GMT
You need the combo box to get the new records once more.  After deleting
the record from the table write:

me.theComboBox.requery
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.