title: How to move item in listBox up and down access VBA?
body: <p>I have a list box contains 10 times . I have UP and Down buttons to move item up and down. My VBA works only if i set listbox multiselect property to 'None'. For the multiselect=simple option it throws error like in valid use of null in this line of code </p>
  
  <pre><code>     sText = lbfNames.Column(0, iIndex)
  </code></pre>
  
  <p>My VBA</p>
  
  <pre><code>    Private Sub cmdUP_Click() 
      Dim sText As String
         Dim iIndex As Integer
         iIndex = lbfNames.ListIndex
         'check: only proceed if there is a selected item
         If lbfNames.ListCount &gt; 1 Then
           'index 0 is top item which can't be moved up!
          If iIndex &lt;= 0 Then
              MsgBox ("Can not move the item up any higher.")
              Exit Sub
          End If
          ' If iIndex = -1 Or lbfNames.ListCount &gt; 1 Then
          'save items text and items indexvalue
          sText = lbfNames.Column(0, iIndex)
          lbfNames.RemoveItem iIndex
          'place item back on new position
          lbfNames.AddItem sText, iIndex - 1
          'if you keep that item selected
          'you can keep moving it by pressing cmdUp
          lbfNames.Selected(iIndex - 1) = True
          iIndex = iIndex - 1
     End If
     End sub
  </code></pre>
  
  <p>And i was trying to convert the below C# code(found in stackoverflow) to Access VBA throwing errors. Some data members not found. </p>
  
  <pre><code>     public void MoveUp()
   {
       MoveItem(-1);
   }
  
   public void MoveDown()
   {
      MoveItem(1);
   }
  
   public void MoveItem(int direction)
   {
      // Checking selected item
      if (listBox1.SelectedItem == null || listBox1.SelectedIndex &lt; 0)
          return; // No selected item - nothing to do
  
      // Calculate new index using move direction
      int newIndex = listBox1.SelectedIndex + direction;
  
      // Checking bounds of the range
      if (newIndex &lt; 0 || newIndex &gt;= listBox1.Items.Count)
          return; // Index out of range - nothing to do
  
      object selected = listBox1.SelectedItem;
  
      // Removing removable element
      listBox1.Items.Remove(selected);
      // Insert it in new position
      listBox1.Items.Insert(newIndex, selected);
      // Restore selection
      listBox1.SetSelected(newIndex, true);
  }
  </code></pre>
  
  <p>Is there anyway to do this in access vba.</p>