More Access Help please, Command Bar Combo Box

How can I grab the value of a Command Bar Combo Box and put it into a string?

I’ve got a list of reports in a combo box. When somebody clicks on either the Custom Print or Preview buttons, off it goes to the code.

But I can’t figure out how to extract the string from what’s been selected in the combo box…

Something along the lines of

Dim strReportName As String

strReportName = CommandBars("tlbReports").Value
DoCmd.OpenReport strReportName, acViewPreview

I’ve tried many things, but this is just an example of what I’m trying to do.

Any ideas?


I’m not sure I understand why you need the CommandBars function at all. What you are trying to do will work, if you simply have a combo box with the list of reports in it. Once the Custom Print or Preview button is pressed, your code will work if you:
[li] change “CommandBars(“tlbReports”).Value” to “cboReport.text”[/li][li] add “cboReport.SetFocus” just before you try to read the text property.[/li][/ul]
If you have to use the CommandBars function for some other reason, let me know why and I’m sure we can figure something out.

Thanks Hardcore,

Unfortunately, there’s not much I can do about the location of the combo box… I’ve been giving the task of coding it… the design was already done for me :slight_smile:

But this box does need to be available from many forms, so having it on a toolbar makes sense…



  1. Make sure “tlbReports” isn’t supposed to be “tblReports”
  2. You have to get the right index in .Controls(?) to reference the correct combo box
  3. Note the .Text property instead of .Value - these controls don’t have a .Value property
  4. You still may need to setfocus prior to reading the text, I really don’t know.

I can’t say much more without seeing an example of what you are working on. If you want to make a sample available somewhere to download, I can be more specific.

Hope this helps!

Thanks Hardcore,

I’d already tried several variations of what you suggested with no luck.

But reading your point #2 really got the 'ol brain churning and I had it working pretty quickly… the answer was quite simple… I’d been using numbers instead of just putting the name of the control!

here’s a snipit of the code involved

Dim strReportName As String

Select Case strFormName

Case "frmBatchShipmentLog"

    strReportName = CommandBars("tlbBatchShipment").Controls("Report List").text

    If IsNull(strReportName) Or Len(strReportName) = 0 Then
        MsgBox "Please Select A Report To Preview"
        Exit Function
        DoCmd.OpenReport strReportName, acViewPreview
    End If

Thanks again!

Oh BTW, tlb standfor TOOLBAR… I would have picked something a bit different from the Table prefix, but it was already done…

See, even when I’m wrong, I’m right. :smiley:

Seriously though, I’m glad that I could help you, even if only a little bit. Part of the programmer’s creed is to always try to help another programmer in need. Just remember to do the same some day for a future newbie.