Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2002
    Posts
    5

    Unanswered: adding items to a combobox in VBA with access97

    I'm trying to add items to a combobox in a VBA from a database, and I can't seem to find a way to do this to a combobox in code?

  2. #2
    Join Date
    Jul 2002
    Location
    Romania
    Posts
    122
    What Row Source Type?

    1. Table/Query or Field List: you can't add items. All you can doe is Requery the combo box.

    2. Value List:

    ComboName.RowSource = YourValue & "; " & ComboName.RowSource
    ComboName = YourValue

    where ComboName is the exact name of the combo box and YourValue is what you want to add to combo (if you enter a string, enclose it in double quotes).

    The code works if run from within the form that contains the combo box. To run it from outside, use the syntax:
    Forms("FormName")("ComboName") instead of ComboName and make sure the form is open.
    The combo will display the new value after the code is run.

    HTH,

    Dan

  3. #3
    Join Date
    Jul 2002
    Posts
    5

    thanks, but

    This works except I can't find a way to spool this from a database. I can setrowsource once, but it just gets overwritten every time after that, and sure I can use the cboname.rowsource = value "; " & cboname.rowsource = ... but I can't find a way to dynamically add new entries?

  4. #4
    Join Date
    Jul 2002
    Location
    Romania
    Posts
    122
    Maybe you should just replace the entire recordsource instead of looking for new entries... This solves the problem of deleted records.

    Dim myrs as DAO.Recordset
    Dim myctr As Control
    Set myrs = CurrentDb.OpenRecordset("TableOrQueryName")
    Set myctr=Forms("FormName")("ComboBoxName")
    With myrs
    Do until .EOF
    myctr.RowSource = myctr.RowSource & !FieldName & "; "
    .MoveNext
    Loop

    In the end, you'll have a fresh list of entries in the combo box.

    HTH

    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •