0
votes

I have an access form with a combobox for Suppliers. I have a '...' button control next to the combobox, which opens a new supplier form if the combobox is empty or goes to the selected supplier if its occupied. My issue is if the user selects a record and then realises its wrong and wants to add a new supplier.

When deleting the supplier name, either by delete button or backspace, the record seems to be still selected. However, the '...' button doesn't work. Trying to navigate away from the record means that I get an error saying You must enter a value in the Order.supplier_ID field.

Is there any way of clearing the selection easily?

Can I clear the selection without this error? Allowing the user to navigate away from the combobox and select the '...' button

Will I need VBA, and where do I even start?

1
Do you use something like this? ComboBox1.Items.Remove(ComboBox1.SelectedItem) - R3uK
No. I'll look in to it!! Where do I put that code? - LiamH
In the flow of your code where you want to delete the selected item... (you need to change ComboBox1. Do you use RowSource property to fill your combobox? - R3uK

1 Answers

0
votes

Something like this should help you :

  1. store the index of selected item
  2. change it to the next one or the previous one
  3. remove the item that was selected before

Here is the code :

Dim SelectedITM As Long

With Order.supplier_ID
    SelectedITM = .SelectedItem
    If SelectedITM <> .ListCount - 1 Then
        .Selected (SelectedITM + 1)
    Else
        .Selected (SelectedITM - 1)
    End If
    .Items.Remove (SelectedITM)
End With