Select Case with Listbox

bd528

Registered User.
Local time
Yesterday, 17:18
Joined
May 7, 2012
Messages
111
Hi all,

I have a listbox on a form, populated by VBA.

The values on the listbox are dynamic, depending on query results, in this way :-

Code:
Me.lstReports.AddItem "Puppy (" & RS.Fields(0) & ")"

I want to create events based when the user double clicks the listbox. I was doing this using a select case, but as the listbox values are dynamic, I'm struggling.

I hoped this would work :-

Code:
Case Left(Me.lstReports.Column(0), 5) = "Puppy"

I added a watch for this, which returns true, but the code in the case statement is skipped.
 
you dont need VB for any of this.
you add fields to a listbox via the query rowsource.
so too, would you put the answers. The result of what you want to do would be in another column.
thus eliminating any vb CASE statement.

BUT,you can use:
Code:
select case true
   Case Left(Me.lstReports, 5) = "Puppy"
          'do something
   Case Left(Me.lstReports, 3) = "Cat"
end select
 
you dont need VB for any of this.
you add fields to a listbox via the query rowsource.
so too, would you put the answers. The result of what you want to do would be in another column.
thus eliminating any vb CASE statement.

BUT,you can use:
Code:
select case true
   Case Left(Me.lstReports, 5) = "Puppy"
          'do something
   Case Left(Me.lstReports, 3) = "Cat"
end select

Excellent, thank you.
 

Users who are viewing this thread

Back
Top Bottom