RE: Deleting Access Records

I have a problem with a ListBox linked to a database...... What I want to do is get the list box's index for an item,
Then delete that Item out of the database..Simple IF you know how (I Don't)

LVL 1
MAVERICKAsked:
Who is Participating?
 
esdhemConnect With a Mentor Commented:
I assume the event is listbox_click?
You need a DB component in your app maybe DAO 3.5 would be cool
it works on Access Tables

declare your DB
Public MyDatabase As Database
Dim MyRecordset As Recordset

you will need to initialize

Public Sub InitializeDatabases()
    Set MyDatabase = OpenDatabase(App.Path + "\MyData.mdb")
End Sub

set myrecordset = mydatabase.openrecordset("MyDataTable",dbopentable)

Now you can edit your DB
use a seek command in conjunction with your index from your listbox.index you capture on the click.
to take care of the situation of an empty table use
if myrecordset.recordcount=0 then
  msgbox"No Record"
else
  myrecordset.delete
  myrecordset.update
endif


0
 
vamsi_kCommented:
Using the list box's index, you could get the item in the list box, and use that item in the loop for searching the database, and if matched, delete that record.  If you still did not get the idea, I will write the code.

Regards,
Vamsi
0
 
MAVERICKAuthor Commented:
I'm familiar with the concept but I really would like some code... I tried to do it similarly to the method you suggested but it didn't work

0
 
MAVERICKAuthor Commented:
I've rejected the answer because I really need the FULL code pretty soon!!
 to do the 'simple'  task.....

0
 
MAVERICKAuthor Commented:
I tried the code....... I still couldn't match it to the index... it... My friend solved the problem.....Thanks....


0
All Courses

From novice to tech pro — start learning today.