Results 1 to 2 of 2

Thread: urgent !! add/remove data in listboxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Location
    Belgium
    Posts
    4

    Exclamation

    Hi,
    First I want to appologize for my bad English,I hope someone will understand me.
    I'm creating a new appliction for my company but I'm stuck.
    Here is my problem.
    So I created a form with a listbox(1) within data based on a table. Then I created another listbox(2) because I have to select several things from listbox(1). So I placed a button on my form and I can add my selected data into listbox(2).
    But I also placed a button on it to remove data from listbox(2) in case of I added something wrong. This also works but when I now want to add new data,he also add the data I already removed. And then second thing I want to use the data of listbox(2) as criteria for a query. It works when I use a combobox but not with a listbox. I already know that I have to work with SQL but I never worked with SQL.
    By th way I work with Access97
    So can someone help me please??
    This is my code

    Option Compare Database

    Option Explicit


    Private Sub Command10_Click()
    On Error GoTo Err_Command10_Click

    DoCmd.Quit

    Exit_Command10_Click:
    Exit Sub

    Err_Command10_Click:
    MsgBox Err.Description
    Resume Exit_Command10_Click

    End Sub


    Sub cmdCopyItem_Click()

    End Sub

    Function CopySelected(frm As Form) As Integer

    End Function

    Private Sub Command50_Click() 'add

    Dim ctlSource As Control
    Dim ctlDest As Control
    Static strItems As String
    Dim intCurrentRow As Integer

    Set ctlSource = lst_bts
    Set ctlDest = lst_selectedbts

    For intCurrentRow = 0 To ctlSource.ListCount - 1

    If ctlSource.Selected(intCurrentRow) Then
    strItems = strItems & ctlSource.Column(0, intCurrentRow) & ";"
    End If
    Next intCurrentRow

    ' Reset destination control's RowSource property.
    ctlDest.RowSource = ""
    ctlDest.RowSource = strItems
    lst_selectedbts.RowSource = strItems
    lst_selectedbts.Requery
    txtSelected_bts.Value = strItems

    End Sub

    Private Sub Command51_Click() 'remove


    Dim ctlDest As Control
    Dim intCurrentRow As Integer
    Dim strItems As String

    Set ctlDest = lst_selectedbts

    For intCurrentRow = 0 To ctlDest.ListCount - 1

    If Not ctlDest.Selected(intCurrentRow) Then
    strItems = strItems & ctlDest.Column(0, intCurrentRow) & ";"
    End If

    Next intCurrentRow
    ctlDest.RowSource = ""
    ctlDest.RowSource = strItems


    End Sub

    Private Sub Form_Click()

    ReDim strSelectie(lst_bts.ListCount - 1)
    txtSelected_bts = ""
    End Sub

    Private Sub Form_Load()

    ReDim strSelectie(lst_bts.ListCount - 1)
    End Sub




  2. #2
    Lively Member dlm's Avatar
    Join Date
    Oct 2000
    Location
    Geraardsbergen(Belgium)
    Posts
    91
    Hi Pieje,

    Your problem is with your

    Static strItem As String

    Didn't you receive my mail...or was I wrong...?


    Ps: My email adress at work is:
    [email protected]

    If you can solve the problem, why worrying about it…
    If you can’t solve the problem, worrying won’t help…

    De la Motte Günther

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width