How to add BOTH static values and records from a table as list items to a combo box in VBA

557 views Asked by At

I have a combo box that gets its list items from a query. But in addition to these items, I need one static option that will be there in all cases.

I tried doing this in the naive way:

Private Sub Form_Open(Cancel As Integer)
   Set rst = CurrentDb.OpenRecordset("SELECT ESDNodes.Description, ESDNodes.Sort FROM ESDNodes WHERE (((ESDNodes.parentID) =" & parentID & ")) ORDER BY ESDNodes.Sort")
   Set nextSiblingSelect.Recordset = rst
   nextSiblingSelect.AddItem Item:="Make Last", Index:=0
End Sub

but end up with this run-time error

The RowSourceType property must be set to 'Value List' to use this method.

which I half-expected.

Is there any trick around this? I suppose I could add a dummy record to my table set and change the query but that would be rather ugly and I would not prefer it.

1

There are 1 answers

2
June7 On BEST ANSWER

Try a UNION query as the combobox RowSource. Maybe like:

SELECT Description, Sort FROM ESDNodes UNION SELECT "Make Last", 0 FROM ESDNodes ORDER BY Sort;