Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active "List Box" selection from button 3

Status
Not open for further replies.

eon5

Technical User
Dec 31, 2007
47
ZA
Good day,

I have a “List Box” with three Report names in it.
The name of the “ListBox” is ViewReport

“Products All”
“Products Phase Out”
“Products Non Phased Out”

Currently I have a macro that opens the correct form in dialog mode the moment I double click on any of the three report names in the “List Box”…and it works perfectly!

I would like to change the procedure by adding a Button next to the “List Box” to replace the Double click function…instead I would like to select the report from the list and then click the Button to open the selected report.

I tried the following code and I lot of other code but don’t seem to get it right.

Private Sub OpenReport_Click()

Dim stDocName As String
stDocName = Me.ViewReport.DefaultValue
DoCmd.OpenReport stDocName, acViewPreview, , , acDialog

End Sub

Any advice will be appreciated.

Thanks
Theuns
 
Something like:
Code:
 stDocName = Me.ViewReport.ItemData(ViewReport.ListIndex)
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Hi there,

You might want to try ".ItemsSelected".

If the list box doesn't have the multiple selection enabled you can get the selected item's name using:

Code:
Private Sub OpenReport_Click()
Dim stReportName As String, ItemNr As Integer

ItemNr = Me.ViewReport.ItemsSelected(0)
stReportName = Me.ViewReport.ItemData(ItemNr)
DoCmd.OpenReport stReportName, acViewPreview

End Sub

Hope this helps

Michiel

 
Why not simply replace this:
stDocName = Me.ViewReport.DefaultValue
with this ?
stDocName = Me.ViewReport.Value

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Good spot PHV, I seem to be a bit too used to writing VB6 [wink]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
If the referred to list box is what I think it is that won't work.

If it's a list box with no inputfield, so you only have the possibility to select and not to type, the values/items returned are:

Me.ViewReport.ItemsSelected(0) --> The index number in the list of the (first) selected item.
Me.ViewReport.ItemData(#) --> The actual value you see where # is the index number.

Me.ViewReport.Value --> Null, because there is no value. Only a selection.


(at least for me it does)
 
MTimmer, strange, works as expected for me (and obviously PHV)

I think you've got the value part of this a bit skewed, here's what VBA help says about what .Value will return with a listbox...
VBA Help said:
The value in the bound column for the item selected in the list.
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Yeah, I forgot about something.

It works with .Value if the list box doesn't have multiple selection enabled. And it does in my case, so that's where I got it wrong. Sorry about that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top