You are here:

Visual Basic/VB for applications - Outlook

Advertisement


Question
In VB for applications I have this code:

Private Sub cc_Change()

End Sub

Private Sub UserForm_Initialize()
   cc.AddItem "op1"
   cc.AddItem "op2"
   cc.AddItem "op3"
   cc.AddItem "op4"

End Sub

The above works.

I would like to further develop this so when you click "op1" you get
associated options, this is the code I have so far;

Private Sub combo2_Change()
   If cc = "op1" Then
   Me.combo2.RowSourceType = "Value List"
   Me.combo2.RowSource = "a; b; c"
   Else
   Me.combo2.RowSourceType = "Value List"
   Me.combo2.RowSource = "default"
   End If
End Sub

I have only listed "op1" as it would be transferable. Please can you help
me, when I select "op1" I don't get the values "a" "b" or "c""

Answer
The only thing I see is you need to add .text on the end of cc

So the following

Private Sub combo2_Change()
  If cc = "op1" Then
  Me.combo2.RowSourceType = "Value List"
  Me.combo2.RowSource = "a; b; c"
  Else
  Me.combo2.RowSourceType = "Value List"
  Me.combo2.RowSource = "default"
  End If
End Sub

would become
Private Sub combo2_Change()
  If cc.text = "op1" Then
  Me.combo2.RowSourceType = "Value List"
  Me.combo2.RowSource = "a; b; c"
  Else
  Me.combo2.RowSourceType = "Value List"
  Me.combo2.RowSource = "default"
  End If
End Sub

Visual Basic

All Answers


Answers by Expert:


Ask Experts

Volunteer


Kevin Watkins

Expertise

I have written several programs integrating with MS Office including Access, Excel, and Word. I have used control arrays as well as data arrays, text files. I have an associates degree in programming. Please do not ask questions about VBA or dot net. I can only answer questions about Visual Basic 6.

Experience

I have written several programs integrating with MS Office including Access, Excel, and Word. I have used control arrays as well as data arrays, text files. I have an associates degree in programming.

Education/Credentials
I have an associates degree in computer programming.

©2016 About.com. All rights reserved.