Full Version: Drop Down Population
UtterAccess Forums > Microsoft® Access > Access Forms
ibwahooka
Hey guys,
Is it possible to get the names of my reports into a drop down on a form? I would like to have the ability to select a report by a drop down and then tie a command button to it to open it. I would then use the open report feature to get the desired report open. Any suggestions?
Thanks in advance,
Shawn
projecttoday
Sure, put the names of the reports in a table and base the combo on that table.
That don't you just make a button for each report?
Robert
norie
Shawn
Create a form, add a combobox and a command button.
Then try this code, changing the names of the controls as required.
CODE
Private Sub Command2_Click()
    If Me.Combo0.Value <> "" Then
        DoCmd.OpenReport Me.Combo0.Value, acViewPreview
    End If
End Sub
Private Sub Form_Load()
Dim db
Dim doc
Dim strReports As String
    Set db = CurrentDb
    With Me.Combo0
        .RowSourceType = "Value List"
    
        For Each doc In db.Containers("Reports").Documents
            .RowSource = .RowSource & doc.Name & ";"
        Next doc
    End With
End Sub
ibwahooka
Thanks Norie,
I'll give that a try.
ibwahooka
Norie,
That worked great! I think I really need to get an Access book that deals with the DAO and ActiveX a little better than the one I have, but here is what my final code looked like.
Private Sub Form_Load()
Dim db As DAO.Database
Dim cnt As DAO.Container
Dim doc As DAO.Document

'Point the db object at a reference to the current database
Set db = CurrentDb

'Point the Container object at the Reports collection of the database
Set cnt = db.Containers("Reports")
With Me.Combo1
.RowSourceType = "Value List"

'Loop through each Document object in the Documents collection
'of the container and populate each row of Combo list
For Each doc In cnt.Documents
.RowSource = .RowSource & doc.Name & ";"
Next doc
End With

End Sub
Thanks again,
Shawn
norie
Shawn
Glad to be of help.
Also good to see you altered my rather sloppy code and typed the variables etc.
ibwahooka
Got one more question. How would I check to make sure that the combo box has a selection in it when the user clicks the button. I've tried Is(Me.Combo1) and it doesn't work. Any ideas??
hawn
ibwahooka
Whoops sorry I've tried IsNull(Me.Combo1) and even Me.Combo1 Is Null and nothing works.
norie
Shawn
The click event code for the command button I posted checks for that.
ibwahooka
Norie,
That's what I thought, but it gives me an invalid use of null statement
norie
Eh, I didn't use a null statement anywhere.frown.gif
Can you post the code you are using?
ibwahooka
If Me.Combo1.Value <> "" Then
MsgBox "Please make a selection"

Exit Sub
End If
norie
Weird, I got no errors with that.
Try this.
CODE
Private Sub Command2_Click()
    If Me.Combo0.ListIndex <> -1 Then
        DoCmd.OpenReport Me.Combo0.Value, acViewPreview
    End If
End Sub

Again change the control names as required.
ibwahooka
Now it works! I have no idea what's going on, but I think I need to stop working on my database.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.