Combo Box New Entry (1 Viewer)

Eljefegeneo

Still trying to learn
Local time
Today, 11:09
Joined
Jan 10, 2011
Messages
904
I am trying to add a new entry to a combo box as a permanent entry.

I have tried

Code:
  Dim myQry As String
    myQry = Me.NewQuery
       Me.cboQuery.AddItem (myQry)
And the module:

Code:
  Dim newQ As String
  newQ = Me.NewQuery
  AddItemCbo cboQuery, newQ
  DoCmd.Save
Where AddItemCbo is

Code:
  Function AddItemCbo(ctrlComboBox As ComboBox, _
   ByVal strItem As String)
   
   ctrlComboBox.AddItem Item:=strItem, Index:=0
   
  End Function
I typed in the original list.

Both add the item very nicely, but, neither saves them to the Combobox list. When I close the form and open it again, the new items(s) are no longer on the combobox list. Limit to list = No and Allow Value List Edits = Yes. Me.NewQuery is a text box. cboQuery is my combobox.

How do I save the new item(s) to the combobox list?
 

Eljefegeneo

Still trying to learn
Local time
Today, 11:09
Joined
Jan 10, 2011
Messages
904
I appreciate you directing me to that link. Reading it all the way down to the end tells me that the .additem is a useless command. What useful purpose does it serve if you can't save the result; note that I tried to save it with the save command but didn't save anything.

Is saving it to a table (it is a list of queries), the only way to do it?
 

Eljefegeneo

Still trying to learn
Local time
Today, 11:09
Joined
Jan 10, 2011
Messages
904
Code:
  Dim myQuery as string
  Set db = CurrentDb
  Set rs = db.OpenRecordset("tblQueries")
  MyQuery = NewQuery
  rs.AddNew
  rs.Fields("QName") = MyQuery
  rs.Update
  rs.Close
  Set rs = Nothing
  Refresh
So, I added a table to the backend, tblQueries. Then added this code to a command button on the form and voila, works fine. But still don’t understand why MS would have a code .additem when it doesn't save it to the combo box.

So, solved and I am moving on. Thanks again to jdraw for pointing me in the right direction.
 

jdraw

Super Moderator
Staff member
Local time
Today, 14:09
Joined
Jan 23, 2006
Messages
15,379
Not sure what queries you are trying to show, but this will give all queries in your database.
Code:
SELECT Name , 'query' as ObjTyp 
FROM MsysObjects 
WHERE  [Name] not Like '~*'   AND 
      MSysObjects.Type = 5
 

Users who are viewing this thread

Top Bottom