Results 1 to 1 of 1
  1. #1
    Join Date
    Apr 2011

    Unanswered: Move item from one listbox to another

    This is code from an Access 2003 database I put together a few years ago and I have attempted to copy it into a new database I am working on in Access 07. After making the necessary changes to the code I keep getting 3 different parameter value pop-up windows. 2 of the pop-ups say the same thing "contacttable.selecteditem" and the third says "selecteditem". I know it has to do with the " & "" stuff but I have tried many different things and I am struggling.

    ( I know there is a space b/w Docmd****nSQL that shouldn't be there. For some reason when I paste it here it turns it into **** so I just added a space there)

    Private Sub SelectedItem(bolSelect As Boolean, Optional strCtl As String)
    On Error GoTo SelectedItem_ERR

    Dim ctl As Control
    Dim varItm As Variant

    DoCmd.SetWarnings False
    If strCtl <> "" Then
    ' set the ctl variable to the appropriate
    ' listbox
    If strCtl = "Listregistered" Then
    Set ctl = Listregistered
    Set ctl = Listattended
    End If
    ' If no selections is made in the appropriate
    ' listbox then tell the user and set the focus
    ' to that listbox
    If ctl.ItemsSelected.Count = 0 Then
    MsgBox "Please make a selection from " & ctl.Name
    GoTo SelectedItem_EXIT
    ' Loop through each item selected
    For Each varItm In ctl.ItemsSelected
    ' Change the Selected field in the table to the value
    ' of bolSelect, where the value of dvtype in the table
    ' equals the one(s) selected in the listbox
    DoCmd. RunSQL "UPDATE Contacttable SET SelectedItem = " & bolSelect & " " & _
    "WHERE ID=" & ctl.ItemData(varItm) & ";"
    Next varItm
    End If

    ' Change the Selected field in the table to the value
    ' of bolSelected for all dvtypes in the table
    DoCmd. RunSQL "UPDATE Contacttable SET SelectedItem = " & bolSelect
    End If



    On Error Resume Next
    DoCmd.SetWarnings True
    Exit Sub


    MsgBox Error$
    Resume SelectedItem_EXIT

    End Sub
    Last edited by crosseydlobster; 05-02-11 at 22:07.

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