oops my mistake I copied the code for one of my other buttons. Here is the right code. For reference the other button changes the item number to the last 3 digits of the part number. This is a company specific request.
Here is the right code:
Public Sub SampleCommandFunction()
'Get the active document which must be a drawing or else it will error
Dim oDrawDoc As DrawingDocument
oDrawDoc = g_inventorApplication.ActiveDocument
'Create an object to store all the sheets called "oSheets"
Dim oSheets As Sheets
oSheets = oDrawDoc.Sheets
'Create an object to store an individual sheet
Dim oSheet As Sheet
'For every sheet in drawing doc
For Each oSheet In oSheets
'Create an object to store all the drawing views
Dim oViews As DrawingViews
oViews = oSheet.DrawingViews
'Create an object to store an individual view
Dim oView As DrawingView
'For ever drawing view on the sheet
For Each oView In oViews
Dim c As Integer
c = 0
'Get the part number associated with the drawing view
Dim oPartNumber As String
oPartNumber = oView.ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(3).Item(2).Value
'Testing Message Box
'MsgBox ("Drawing View " + oPartNumber)
'Create an object to store all the boms
Dim oBoms As DrawingBOMs
oBoms = oDrawDoc.DrawingBOMs
'Create an object to store an individual bom
Dim oBom As DrawingBOM
'For every bom in the drawing
For Each oBom In oBoms
'Locate where the MPN & Item Columns Are
'Loop through all the BOM headers to find the columns and then save the column number they are in
Dim oMPNCol As Integer
For i = 1 To oBom.DrawingBOMColumns.Count
Dim oFindMPN As String
oFindMPN = oBom.DrawingBOMColumns.Item(i).Title
If oFindMPN = "MPN" Then
oMPNCol = i
End If
Next
Dim oFindItemNumCol As Integer
For i = 1 To oBom.DrawingBOMColumns.Count
Dim oFindItemNum As String
oFindItemNum = oBom.DrawingBOMColumns.Item(i).Title
If oFindItemNum = "ITEM" Then
oFindItemNumCol = i
End If
Next
'Store Bom reference assembly
Dim RefAssemblyLong As String
RefAssemblyLong = oBom.ReferencedDocumentDescriptor.DisplayName
'Count how many characters in RefAssembly
Dim oLengthAssembly As Integer
oLengthAssembly = Len(RefAssemblyLong)
'Assembly name without .iam (4 characters)
Dim RefAssembly As String
RefAssembly = Left(RefAssemblyLong, oLengthAssembly - 4)
'For every row in the BOM
For i = 1 To oBom.DrawingBOMRows.Count
'Get the MPN number for the Bom Item
Dim oMPN As String
oMPN = oBom.DrawingBOMRows.Item(i).Item(oMPNCol).Value
Dim oItem As String
oItem = oBom.DrawingBOMRows.Item(i).Item(oFindItemNumCol).Value
If oView.ViewType <> DrawingViewTypeEnum.kDetailDrawingViewType And oPartNumber = oMPN Then
oView.Label.FormattedText = ("DETAIL ITEM " & oItem & vbCrLf & "MPN NUMBER " & oPartNumber)
End If
Next
Next
Next
Next
MsgBox("Detail Views Have Been Updated With Item Number")
End Sub