Reputation: 23
I have a user form that runs when a cable shape is dropped onto the sheet: The form asks the user whether the cable classification is primary or secondary and whether the tray type is primary or secondary. If, for example a primary cable and tray is chosen, then the cable type+tray shape data will change to drop down lists only containing primary cables and trays.
Public shp3 As Shape
Private Sub CommandButton1_Click()
Dim CableClass As String
Dim TrayClass As String
Dim pg2 As Page
CableClass = ComboBox1.Value
TrayClass = ComboBox2.Value
Set shp3 = ActivePage.Shapes.ItemFromID(cID)
If CableClass = "Primary" Then
shp3.Cells("Prop.Row_CableClass.Value").FormulaU = """Primary"""
shp3.Cells("Prop.Row_CableType.Format").FormulaU = """Cable 1;Cable
2;Cable 3;Cable 4"""
ElseIf CableClass = "Secondary" Then
shp3.Cells("Prop.Row_CableClass.Value").FormulaU = """Secondary"""
shp3.Cells("Prop.Row_CableType.Format").FormulaU = """Cable 1;Cable
2;Cable 3;Cable 4"""
End If
If TrayClass = "Primary" Then
shp3.Cells("Prop.Row_TrayClass.Value").FormulaU = """Primary"""
shp3.Cells("Prop.Row_TrayType.Format").FormulaU = """cable tray
1;cable tray 2;cable tray 3;cable tray 4"""
ElseIf TrayClass = "Secondary" Then
shp3.Cells("Prop.Row_TrayClass.Value").FormulaU = """Secondary"""
shp3.Cells("Prop.Row_TrayType.Format").FormulaU = """cable tray
1;cable tray 2;cable tray 3;cable tray 4"""
End If
Unload Me
End Sub
Once a specific type of cable or tray is chosen from the shape data, I want the cost to automatically change based on what is selected. In other words, I want one piece of shape data (cost) to change dynamically based on the type of cable selected from a drop down box.
Upvotes: 0
Views: 265
Reputation: 2438
You can also do some powerful things in the ShapeSheet
without having to resort to VBA. You can force the question (input of data) on shape drop, and then use the properties (Prop.x
, User.x
) to set up your drop down lists.
Looking at your provided code, you are following the same sort of actions as you would in the ShapeSheet
, just using a different syntax/language/interface. The logic is similar, you set up a User
property (or rather two, because you are looking at cables and trays) that returns true or false depending on whether you have "Primary" or "Secondary" selected. You then use that Boolean
result to return the appropriate string of choices.
I don't have Visio on this machine to provide a specific example - I have used this technique to change colours of shapes and even change the geometries.
Upvotes: 0
Reputation: 5687
Not a full answer, but much too long/complex for just a comment:
In your user form code behind:
Private Sub CableClass_Change()
SetCableClassValues CableClass, shape
End Sub
Private Sub TrayClass_Change()
SetTrayClassValues TrayClass, shape
End Sub
In a separate Standard Module:
Public Sub SetCableClassValues (ByVal cableClass as ComboBox, ByVal theShape as Visio.Shape)
theShape.Cells("Prop.Row_CableClass.Value").FormulaU = """Primary"""
theShape.... 'set the appropriate cost value here
End Sub
Public Sub SetTrayClassValues (ByVal trayClass as ComboBox, ByVal theShape as Visio.Shape)
theShape.Cells("Prop.Row_CableClass.Value").FormulaU = """Primary"""
theShape.... 'set the appropriate cost value here
End Sub
Note that is all "air-coding" so it won't work exactly as written. Once you're in the SetCableClassValues
routine, though, you'll have access to everything in the cableClass
combo box, just as if you were directly in the code-behind. You'll also have access to theShape
- whichever one it is that you have as shp3
in your existing code which you'll pass in as the shape
parameter.
If you need both bits of info to determine the costing, then you'll have 1 routine that will take both comboboxen and the shape as parameters, ensure both have valid values selected, then do all the updating.
I'm not at all familiar with the Visio object model, so you'll have to figure out how to set the cost, but it looks like you've got enough understanding to handle that part.
Upvotes: 1