Results 1 to 7 of 7
  1. #1
    KatiS is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    3

    Listbox

    Hi

    I am new to Access. I am trying to create a form which has a listbox related to my table and 2 buttons. One to add a new item to list box(Add new record) and one to remove.

    The code for remove is this
    Private Sub List0_Click()
    Dim SelectCost As String
    Dim RNo As Integer

    TempVars("SelectCost").Value = Me!List0.ItemData(Me!List0.ListIndex)
    End Sub
    Private Sub Remove_Cost_ID_Click()
    Dim strQuery As String
    Dim IDToDelete As String



    IDToDelete = TempVars("SelectCost").Value
    If IDToDelete <> "" Then
    strQery = " delete dbo.cost_centres where cost_id = '" & IDToDelete & "' "
    DoCmd.RunSQL strQery
    End If

    End Sub


    But it does not work. I get error message that the operand is missing.

    Would you please help me?

    Thank you

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    You need to mention the source from where you are deleting.
    like DELETE FROM yourTableName

    See http://www.techonthenet.com/sql/delete.php

  3. #3
    KatiS is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    3
    Thank you . the delete command was working in SQL but not in Access!!

    I need one more help.

    The event deletes the record now but my list box still shows the item. How can I refresh it ?

    Thank you

  4. #4
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Me.ListBoxName.Requery

  5. #5
    drexasaurus's Avatar
    drexasaurus is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Santa Ana, CA
    Posts
    60
    List0.Requery is the command. I find it helpful to review the API for objects I use frequently. I searched "listbox msdn access" and found this link: http://msdn.microsoft.com/en-us/libr.../ff195480.aspx.

  6. #6
    KatiS is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    3
    Thank you all

    My form is working now

  7. #7
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Glad to help. Mark the thread as solved.

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

Similar Threads

  1. Replies: 4
    Last Post: 06-24-2013, 07:34 AM
  2. Replies: 3
    Last Post: 12-13-2012, 04:40 AM
  3. Replies: 1
    Last Post: 09-10-2012, 11:21 PM
  4. Replies: 1
    Last Post: 07-26-2012, 11:45 AM
  5. Replies: 7
    Last Post: 06-05-2012, 03:22 PM

Tags for this Thread

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