Refresh/Requery Combobox problems

Michael Carn-Bennett picture Michael Carn-Bennett · Jan 23, 2013 · Viewed 11.2k times · Source

Afternoon,

I have having problems getting my ComboBox to update while the form it is on is open.

My data changes while the form is open, so the ComboBox needs to be refreshed as such but I can't work out how. It seems the only way is to close and then reopen the form, but I don’t real

The ComboBox's raw source is a Simple Select query. I have tried using requery, but it doesn’t seem to do anything.

Sub ComboBox_GotFocus()

Me.ComboBox.Requery

End Sub

Any ideas?

Cheers, Michael

Answer

html_programmer picture html_programmer · Jan 23, 2013

Empty and re-fill the combobox.
The easiest would be:

sSQL_Select = "SELECT * FROM SOMETABLE" 

Me.lstListBox.RowSource = "" 
Me.lstListBox.RowSource = sSQL_Select

Instead of using the SQL Query, you can also explicitly add values to a listbox.
In this you can do something like:

Dim iList_Cnt As Integer
Dim iCnt As Integer

iList_Cnt = Me![lstListBox].ListCount

For iCnt = 0 To iList_Cnt - 1
    Me![lstListBox].RemoveItem 0
Next

Followed by refilling the listbox:

lstListbox.AddItem("Smtg_Col1;Smtg_Col2;Smtg_Col3")

Loop through the combobox for adding multiple rows.