Opening Forms/Reports from Listbox

  • Thread starter Thread starter DenBis via AccessMonster.com
  • Start date Start date
D

DenBis via AccessMonster.com

Good day,

My search for answers to my question is not very successful…

I have a listbox on a form (lstTask). Its source is a table with two fields:
[Task] (visible to the user) and [Item] (lstTask.Column(2) - hidden from the
user). [Task] is a quick description of what the user can open – specifically
reports OR forms. [Item] is the name of the report of form and will always
begin with “frm” or “rpt”.

i.e. [Task] [Item]
“Open Pubs Checklist” “rptPubsChecklist”
“Open OPI Entry form” “frmOPIEntry”

Basically, on the double-click event of lstTask, I want to check if [Item]
begins with “rpt” or “frm”, then open the report or form based on the [Item]
value.

I have been experimenting with a few ideas, however, (1) it would be
downright embarrassing for me to share them with you; (2) they are not
working; and (3) I am having a hard time remembering where it all started….

Any assistance is appreciated.

Thank you

DenBis
 
DenBis said:
Good day,

My search for answers to my question is not very successful.

I have a listbox on a form (lstTask). Its source is a table with two
fields: [Task] (visible to the user) and [Item] (lstTask.Column(2) -
hidden from the user). [Task] is a quick description of what the user
can open - specifically reports OR forms. [Item] is the name of the
report of form and will always begin with "frm" or "rpt".

i.e. [Task] [Item]
"Open Pubs Checklist" "rptPubsChecklist"
"Open OPI Entry form" "frmOPIEntry"

Basically, on the double-click event of lstTask, I want to check if
[Item] begins with "rpt" or "frm", then open the report or form based
on the [Item] value.

I have been experimenting with a few ideas, however, (1) it would be
downright embarrassing for me to share them with you; (2) they are not
working; and (3) I am having a hard time remembering where it all
started..

Select Case Left(Me.lstTask.Column(1), 3)
Case "frm"
DoCmd.OpenForm Me.lstTask.Column(1)
Case "rpt"
DoCmd.OpenReport Me.lstTask.Column(1)
End Select

The .Column() index starts at zero so Column(1) actually refers to the
second column.
 
I am assuming this is Not a MultiSelect list box. If it is, post back for a
different solution.

Put the following in the DoubleClick event of your list box:

Dim strObject As String
dim intItem as Integer

intItem = Me.MyListBox.ItemsSelected(0)
strObject = Me.MyListBox.ItemData(intItem)
If Left(strObject,3) = "frm" Then
DoCmd.OpenForm strObject......
Else
DoCmd.OpenReport strObject....
End If
 
Thanks Rick,
It worked like a charm and I learned a new function! (Left)......

Cheers
DenBis
 
Back
Top