Results 1 to 3 of 3
  1. #1
    Fatti is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    18

    Delete DB Value from Listbox

    I have a form whereby I can add an event. I choose a date and discipline and save button and thats the event. It also adds this event to a listbox on the same form so you can see the events that have been added. The adding works and all is fine.



    The issue I am having is deleting an event by selecting a value from the listbox. I cant seem to return any value that I have selected and even putting a messagebox in to see the values, returns null each time so I can populate the variable to put int the SQL code to match the record to delete.

    Ive searched the site with a couple of solutions but none seem to resolve the problem I am having.

    You can see here im trying all sorts just to get the value selected from the list box:
    Code:
    Public Sub lstShoot_Click()
    
    Dim lstShootValue As String
    Dim varItem       As Variant
    Dim ctl As Control
    Set ctl = Me.lstShoot
    
    'lstShootValue = Me.lstShoot.ItemData(0)
    'lstShootValue = Me![lstShoot].Column(0)
    lstShootValue = CStr(ctl.ItemData(varItem))
    
    MsgBox ("Value = " & lsShootValue)
    
    End Sub
    Whats going on here? It shouldn't be this difficult.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Fatti View Post
    I have a form whereby I can add an event. I choose a date and discipline and save button and thats the event. It also adds this event to a listbox on the same form so you can see the events that have been added. The adding works and all is fine.

    The issue I am having is deleting an event by selecting a value from the listbox. I cant seem to return any value that I have selected and even putting a messagebox in to see the values, returns null each time so I can populate the variable to put int the SQL code to match the record to delete.

    Ive searched the site with a couple of solutions but none seem to resolve the problem I am having.

    You can see here im trying all sorts just to get the value selected from the list box:
    Code:
    Public Sub lstShoot_Click()
    
    Dim lstShootValue As String
    Dim varItem       As Variant
    Dim ctl As Control
    Set ctl = Me.lstShoot
    
    'lstShootValue = Me.lstShoot.ItemData(0)
    'lstShootValue = Me![lstShoot].Column(0)
    lstShootValue = CStr(ctl.ItemData(varItem))
    
    MsgBox ("Value = " & lsShootValue)
    
    End Sub
    Whats going on here? It shouldn't be this difficult.
    What data type is the bound column of the list box? Text, Long, Integer?

    If your list box is NOT multi-select, then try this:


    Code:
    Public Sub lstShoot_Click()
    
    Dim ctl As Control
    
    Set ctl = Me.lstShoot
    
    MsgBox "List Value selected is "  & ctl 
    
    ' or you could use
    ' MsgBox "List Value selected is " & Me.lstShoot
    
    End Sub

  3. #3
    Fatti is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    18
    Its not multi-select and that works perfectly. Much appreciated.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Listbox
    By mikejames in forum Forms
    Replies: 1
    Last Post: 10-25-2011, 07:53 AM
  2. listbox help
    By imintrouble in forum Access
    Replies: 2
    Last Post: 10-20-2011, 01:53 PM
  3. Trying to Delete record using delete query
    By MooseOTL in forum Access
    Replies: 13
    Last Post: 10-04-2011, 02:30 AM
  4. Replies: 11
    Last Post: 03-30-2011, 01:08 PM
  5. Listbox Help
    By allykid in forum Programming
    Replies: 2
    Last Post: 03-30-2011, 06:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums