If in VBA

razorking

Registered User.
Local time
Today, 06:41
Joined
Aug 27, 2004
Messages
332
I am new to VBA so this is probably elementary, but I am stumped.

I have a form with a listbox. I would like to have a different function happen when you double click on a value in the list box based upon another value in a text box.
So if the value in the text box is "A" it would maybe open a report when double clicked. If the value were "B" it might open another form when double clicked etcetera.

I have been able to get it to do a single thing or nothing (depending on the value in the text box) but am unsure of how to make it perform a second or third option. Must be an Else If or something but no luck so far.

Here is what I do have that works:

Private Sub searchlist_DblClick(Cancel As Integer)

Dim link As String
If Me.Text8 = "A" Then
link = Me.searchlist.Column(1)
Application.FollowHyperlink link
End If

End Sub


Thanks!
 
I would adopt in your case a Select Case statement; it is more efficient, more readable and easy to maintain.

filo65
 
Right, I have no idea what you mean but I believe you are most likely correct.

I will get some sleep and try and figure it out tomorrow morning.
 
Me.Text8 => Me.Text8.Value

If your listbox has only one column.. then

change: link = Me.searchlist.Column(1)
to: link = Me.searchlist.Column(0)

-modest
 
filo65 said:
I would adopt in your case a Select Case statement; it is more efficient, more readable and easy to maintain.

filo65


After doing some research I think you led me correctly for what I need.

Thanks!
 

Users who are viewing this thread

Back
Top Bottom