|
-
Expensive Sushi
VB Listview ActiveX Control Question
Ok, this is using the MS Common Control Dialog. I'm writing a program for one of my classes and am stuck fast on one part. This should give you enough info to help me out.
I'm modifying a previous assignment we had so that instead of using CSV files as a database, it uses Access (mdb) files. I have an existing mdb that contains one table. The main form contains a listview window that is used to display the information contained within the mdb file. I've already created the intial display and Add procedures. But I'm having trouble with the Update and Delete Procedures.
My problem is that I can't figure out how to pull a value from the currently selected item in the Listview. When a user clicks on a book in the Listview they can choose to Update or Delete that entry. However, I can't figure out how to call up the correct record inside the mdb file that corresponds to the selection the user made. The "ISBN" column is the primary key (the value I want to search the mdb for).
I understand that I can search for a particular record by using
call datBooks.Recordset.FindFirst("ISBN = '" & ISBN & "'")
And I can pull the record number by declaring RecNbr as a Long variable and using
RecNbr = Clng(Mid(lvwBooks.SelectedItem.Key, 2))
But how the heck do I pull the ISBN from the selected item in the listview and pass it to the Database using the FindFirst method?
Any help is appreciated (although the lab is due by 10:00 pm), any immediate assistance would be great help. Hopefully this post made sense. This is all that I have left to do for the assignment and I've tried everything I can think of.
thanks,
Deadsnows
-
Catfish
There's an easier way: When you populate the listview with the listview.listitems.add command, make the ISBN number you have the tag for that item.
EX:
dim tItem as ListItem
set tItem = listviewname.listitems.add(,,recordsetname.book_name)
tItem.Tag = recordsetname.ISBN
This way you can get the correct ISBN number for a selected item by using listitemname.selecteditem.tag
Duct tape is like the Force. It has a light side, a dark side, and it holds the universe together...
-
Expensive Sushi
Thanks for the tip...That's what I ended up doing anyway. I was populating the Listview with the listview.listitems.add command and using the ISBN. What I was having trouble with was when executing the
call datBooks.Recordset.FindFirst("ISBN = '" & ISBN & "'")
I wasn't sure what to set the ISBN variable equal to. Turns out it was just listview.selecteditem.text. D'oh! always the easy stuff. I got the assignment in on time, however. 
I didn't know about that tItem.Tag = recordsetname.ISBN...pretty cool, I have to mess with that on my semester project.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|