Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Custom Toolbar with combobox (2002/SR-1)

    I'm attempting to move a combobox that I use on one of my forms to a custom toolbar. This combobox is used for adding and going to bookmarks that have been set. I'm getting a runtime error using the test code below.


    <pre>Sub ToolbarUpdate()
    Dim rst As New ADODB.Recordset
    Dim CBar As CommandBar
    Dim CBarCtl As CommandBarControl
    Set CBar = CommandBars("Sample Toolbar")
    Set CBarCtl = CBar.Controls(1)
    rst.Open "tblBookmarks", CurrentProject.Connection, adOpenStatic, adLockOptimistic

    If rst.EOF And rst.BOF Then
    CBarCtl.AddItem "<< Add Bookmark >>"
    Else
    Do Until rst.EOF
    CBarCtl.AddItem rst!LastNameBM & ", " & rst!FirstNameBM
    Loop
    End If

    End Sub</pre>

    The runtime error is:
    Runtime error '-2147467259(80004005)'
    Method 'Add Item' of object '_commandbarcombobox' failed

    I have a reference set to Microsoft Office Object library 10.0

    Any suggestions?
    Thanks,
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Custom Toolbar with combobox (2002/SR-1)

    You have a couple of problems. First, you need to add an adCmdTable option argument to your rs.Open line so the engine knows exactly what kind of recordset it's opening. Then you need an rst.MoveNext after the .AddItem. You should also destroy your recordset object after you finish with it.
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Custom Toolbar with combobox (2002/SR-1)

    Thank you Charlotte! Super help and great advise once again!

Posting Permissions

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