That was one of the things I tried and found that it had the exact same issue except you had to hit apply for every change. Like, the form defaults to C3x4.1 channel. Hit the dropdown, select C5 channel but weight still shows the dropdown for C3 and 4.1 is selected. Hit apply, list updates to C5 weight sizes (however 4.1 is still the active size). No part record exists for C5x4.1 so msgbox opens.
It's kind of hard to explain without watching it but... notice how the form starts off with C3x4.1, when you can change the channel size to C5 the weight is still set to 4.1 and because there's no C5x4.1 it throws the material doesn't exist msgbox. The way to fix this is to make the weight default to the first value if the weight for C3 doesn't equal 4.1, 5 or 6...except that's a lot of coding. The next best alternative would be
If Size = C3 then
If Weight < 4.1 or Weight > 6 then Weight = 4.1
Except other channel sizes have weights in between 4.1 and 6 so the frequency of the error is reduced but it's not really solved since something like C3x5.4 would trigger the alert (5.4 is a weight for C4).
I sort of solved it for angle iron but the amount of coding was frustrating and it doesn't work with C-Channel
Else If verticalLeg = 2.5 Then
If horizLeg < 1.5 Or horizLeg > 2.5 Or horizLeg = 1.75 Or horizLeg = 2.25 Then horizLeg = 1.5
If webWidth < .125 Or webWidth > .5 Then webWidth = .1875
MultiValue.SetList("horizLeg", 1.5,2,2.5)
The entire code is here. It's long
Public Sub Main()
Dim materialOption1 As String
Dim materialOption2 As String
Dim subOpt1 As Double
Dim subOpt2 As Double
Dim subOpt3 As Double
Dim subOpt4 As Double
Dim curPart As Inventor.PartDocument = ThisDoc.Document
Dim epicorNumber As String
Dim extfeat = Feature.InventorFeature("Extrusion1")
Dim epicMatMod As String
Dim visDesc As String
Dim partMaterial As String
Dim epicMatNumber As String = "351-0"
Dim epicMatType As String = "Channel"
oLibraryName = "Autodesk Material Library"
Dim assetLib As AssetLibrary
assetLib = ThisApplication.AssetLibraries.Item(oLibraryName)
extfeat.Suppressed = True
ThisDoc.Document.ObjectVisibility.Sketches = True
MultiValue.UpdateAfterChange = True
materialOption1 = "ASTM A36"
materialOption2 = "Aluminum"
MultiValue.SetList("channelMaterial", materialOption1, materialOption2)
If channelMaterial = materialOption1 Then
'oLibraryName = "Autodesk Material Library"
'Dim assetLib As AssetLibrary
'assetLib = ThisApplication.AssetLibraries.Item(oLibraryName)
ThisApplication.ActiveMaterialLibrary = assetLib
iProperties.Material = "Steel ASTM A36"
MultiValue.SetList("channelSize", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C12", "C15")
If channelSize = "C3" Then
Grip = .273
Dim_d = 3
subOpt1 = 4.1
subOpt2 = 5
subOpt3 = 6
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 1.41
Dim_tw = .17
Else If chanWeight = subOpt2 Then
Dim_bf = 1.498
Dim_tw = .258
Else If chanWeight = subOpt3 Then
Dim_bf = 1.596
Dim_tw = .356
End If
Else If channelSize = "C4" Then
Grip = 0.296
Dim_d = 4
subOpt1 = 5.4
subOpt2 = 7.25
MultiValue.SetList("chanWeight", subOpt1, subOpt2)
If chanWeight = subOpt1 Then
Dim_bf = 1.584
Dim_tw = .184
Else If chanWeight = subOpt2 Then
Dim_bf = 1.721
Dim_tw = 0.321
End If
Else If channelSize = "C5" Then
Dim_d = 5
Grip = 0.32
subOpt1 = 6.7
subOpt2 = 9
MultiValue.SetList("chanWeight", subOpt1, subOpt2)
If chanWeight = subOpt1 Then
Dim_bf = 1.75
Dim_tw = 0.19
Else If chanWeight = subOpt2 Then
Dim_bf = 1.885
Dim_tw = 0.325
End If
Else If channelSize = "C6" Then
Dim_d = 6
Grip = 0.343
subOpt1 = 8.2
subOpt2 = 10.5
subOpt3 = 13
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 1.92
Dim_tw = 0.2
Else If chanWeight = subOpt2 Then
Dim_bf = 2.034
Dim_tw = 0.314
Else If chanWeight = subOpt3 Then
Dim_bf = 2.157
Dim_tw = 0.437
End If
Else If channelSize = "C7" Then
Dim_d = 7
Grip = 0.366
subOpt1 = 9.8
subOpt2 = 12.25
subOpt3 = 14.75
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.09
Dim_tw = 0.21
Else If chanWeight = subOpt2 Then
Dim_bf = 2.194
Dim_tw = 0.314
Else If chanWeight = subOpt3 Then
Dim_bf = 2.299
Dim_tw = 0.419
End If
Else If channelSize = "C8" Then
Dim_d = 8
Grip = 0.39
subOpt1 = 11.5
subOpt2 = 13.75
subOpt3 = 18.75
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.26
Dim_tw = 0.22
Else If chanWeight = subOpt2 Then
Dim_bf = 2.343
Dim_tw = 0.303
Else If chanWeight = subOpt3 Then
Dim_bf = 2.527
Dim_tw = 0.487
End If
Else If channelSize = "C9" Then
Dim_d = 9
Grip = 0.413
subOpt1 = 13.4
subOpt2 = 15
subOpt3 = 20
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.433
Dim_tw = 0.233
Else If chanWeight = subOpt2 Then
Dim_bf = 2.485
Dim_tw = 0.285
Else If chanWeight = subOpt3 Then
Dim_bf = 2.648
Dim_tw = 0.448
End If
Else If channelSize = "C10" Then
Dim_d = 10
Grip = 0.436
subOpt1 = 15.3
subOpt2 = 20
subOpt3 = 25
subOpt4 = 30
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3, subOpt4)
If chanWeight = subOpt1 Then
Dim_bf = 2.6
Dim_tw = 0.24
Else If chanWeight = subOpt2 Then
Dim_bf = 2.739
Dim_tw = 0.379
Else If chanWeight = subOpt3 Then
Dim_bf = 2.886
Dim_tw = 0.526
Else If chanWeight = subOpt4 Then
Dim_bf = 3.033
Dim_tw = 0.673
End If
Else If channelSize = "C12" Then
Dim_d = 12
Grip = 0.501
subOpt1 = 20.7
subOpt2 = 25
subOpt3 = 30
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.942
Dim_tw = 0.282
Else If chanWeight = subOpt2 Then
Dim_bf = 3.047
Dim_tw = 0.387
Else If chanWeight = subOpt3 Then
Dim_bf = 3.17
Dim_tw = 0.51
End If
Else If channelSize = "C15" Then
Dim_d = 15
Grip = 0.65
subOpt1 = 33.9
subOpt2 = 40
subOpt3 = 50
MultiValue.SetList(chanWeight, subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 3.4
Dim_tw = 0.4
Else If chanWeight = subOpt2 Then
Dim_bf = 3.52
Dim_tw = 0.52
Else If chanWeight = subOpt3 Then
Dim_bf = 3.716
Dim_tw = 0.716
End If
End If
End If
MultiValue.SetValueOptions(True, DefaultIndex := 0)
epicMatMod = ""
If channelSize = "C12" And chanWeight = 25 Then epicMatMod = "0075"
If channelSize = "C10" And chanWeight = 30 Then epicMatMod = "0074"
If channelSize = "C10" And chanWeight = 25 Then epicMatMod = "0073"
If channelSize = "C10" And chanWeight = 20 Then epicMatMod = "0072"
If channelSize = "C10" And chanWeight = 15.3 Then epicMatMod = "0070"
If channelSize = "C9" And chanWeight = 20 Then epicMatMod = "0069"
If channelSize = "C9" And chanWeight = 15 Then epicMatMod = "0068"
If channelSize = "C9" And chanWeight = 13.4 Then epicMatMod = "0067"
If channelSize = "C8" And chanWeight = 18.75 Then epicMatMod = "0066"
If channelSize = "C8" And chanWeight = 13.75 Then epicMatMod = "0065"
If channelSize = "C8" And chanWeight = 11.5 Then epicMatMod = "0064"
If channelSize = "C7" And chanWeight = 14.75 Then epicMatMod = "0058"
If channelSize = "C7" And chanWeight = 12.25 Then epicMatMod = "0063"
If channelSize = "C7" And chanWeight = 9.8 Then epicMatMod = "0062"
If channelSize = "C6" And chanWeight = 13 Then epicMatMod = "0055"
If channelSize = "C6" And chanWeight = 10.5 Then epicMatMod = "0057"
If channelSize = "C6" And chanWeight = 8.2 Then epicMatMod = "0079"
If channelSize = "C5" And chanWeight = 9 Then epicMatMod = "0050"
If channelSize = "C5" And chanWeight = 6.7 Then epicMatMod = "0054"
If channelSize = "C4" And chanWeight = .25 Then epicMatMod = "0053"
If channelSize = "C4" And chanWeight = 6.25 Then epicMatMod = "0052"
If channelSize = "C4" And chanWeight = 5.4 Then epicMatMod = "0051"
If channelSize = "C3" And chanWeight = 6 Then epicMatMod = "0049"
If channelSize = "C3" And chanWeight = 5 Then epicMatMod = "0047"
If channelSize = "C3" And chanWeight = 4.1 Then epicMatMod = "0046"
epicorNumber = epicMatNumber & epicMatMod
epicorParamNumber = epicorNumber
If channelMaterial = materialOption1 Then
visDesc = epicMatType & " - " & channelSize & "x" & chanWeight & " " & " - " & materialOption1
End If
iProperties.Value("Custom", "Visual Part Number") = epicorNumber
iProperties.Value("Custom", "Visual Description") = visDesc
If Length > .1 Then
extfeat.Suppressed = False
ThisDoc.Document.ObjectVisibility.Sketches = False
If Len(epicorParamNumber) < 7 Then Call EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
End If
End Sub
Function EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
alert1 = MsgBox("Epicor number for selected material does not exist, do you need this size?", vbYesNo, "Alert")
If alert1 = vbYes Then alert2 = MsgBox("Create request for material to be added to Epicor and template?", vbYesNo)
If alert2 = vbYes Then
Try
oOApp = CreateObject("Outlook.Application")
oOMail = oOApp.CreateItem(0)
Catch
MessageBox.Show("Error in request. Please email the request to e.frissell@linkeng.com", "Failed Error")
Exit Function
End Try
strbody = "<p style='font-family:calibri;font-size:16'>" & _
"This is an automated request for " & visDesc
'"This is an automated request for " & partMaterial & " " & epicMatType & " with vertical leg " & verticalLeg & ", horizontal leg " & horizLeg & ", and web width " & webWidth & vbCrLf
strbody += "<br /><br />"
strbody += "Epicor Identifier - " & epicorNumber & vbCrLf
strbody += "<br /><br />"
strbody += "Visual Description - " & visDesc
With oOMail
.bodyformat = 2
.To = "plzdon'temailme"
.CC = ""
.BCC = ""
.Subject = "Epicor Material Request " & partMaterial & " - " & epicMatType
.Display 'Toggle this for a Signature on/off
End With
With oOMail
'
.HTMLbody = strbody & vbNewLine & .HTMLBody ' add the signature without losing the HTML-formatting of the signature
'.Attachments.Add (FilePath & "\" & StockNum & ".jpg")
'.Display 'Toggle ON to show the Email Window
End With
End If
If alert1 = vbNo Or alert2 = vbNo Then Exit Function
End Function
There was also code that said if weight <> subOpt1 or weight <> subOpt2 or weight <> subOpt3 then weight = subOpt1 except that code didn't work, I think, due to conversion errors. Couldn't get a double for equals to work and basically gave up on it. Last ditch effort to prevent the box from popping up needlessly was to hide it in the if length > .1 statement