| re: Set Toolbar Combobox items when Toolbar is called?
For anyone having a similar problem, I figured out the solution:
Function RepopulateToolbarCombo(myStoredProcedureName As String,
myToolbarName As String, myComboName As String)
On Error GoTo myErr
Dim objBar As Object, objCbo As Object
Dim RS As ADODB.Recordset
Dim myColumnName as string
myColumnName = "SomeColumnName" 'change this to the name of the
column in the stored procedure you wish to use to populate your
combobox
Set RS = CurrentProject.Connection.Execute("EXEC " &
myStoredProcedureName)
Set objBar = Application.CommandBars(myToolbarName)
Set objCbo = objBar.Controls(myComboName)
With objCbo
.Clear 'clear the old values
If Not RS.BOF And Not RS.EOF Then
Do While Not RS.EOF
.AddItem Nz(RS(myColumnName)) 'populate combobox with
each value in the stored procedure
RS.MoveNext
Loop
End If
End With
myExit:
On Error Resume Next
RS.Close
Set RS = Nothing
Set objCbo = Nothing
Set objBar = Nothing
Exit Function
myErr:
MsgBox err.number & " " & err.description
Resume myExit
End Function |