joshuamoloney

Update text in text element then disappears

Discussion created by joshuamoloney on Sep 8, 2011
Latest reply on Sep 12, 2011 by joshuamoloney
Greetings,

I have setup a procedure where the follwoing occurs:
1) The user clicks the layout button
2) Inputbox appears asking for job number
3) Existing text element in the layout view is updated with the job number, the month and the year

This all works perfectly however if the user then goes back to data view and back to the layout view again the text element disappears. Is there a way to save the element or update it permenantly?

Here is my code:
Dim txtType As String
Dim DocInfo As String
Set pMxDoc = Application.Document

'get the label properties the user wants
If Not bTest Then  'test to see if it has been done yet
    If pMxDoc.ActiveView Is pMxDoc.PageLayout Then
        bTest = True
        txtType = InputBox("Enter the Job ID number, or just hit enter if not applicable", "Do you want to display job ID number?")
        If Len(txtType) > 0 Then
'I have replaced the business name with XXXXs for obvious reasons...
            DocInfo = "XXXXXXX XXXXXXX XXXXXXX" & txtType & ", " & MonthName(Month(Date)) & " " & Year(Date)
        Else
            DocInfo = "XXXXXXX XXXXXXX XXXXXXX, " & MonthName(Month(Date)) & " " & Year(Date)
        End If
    End If
End If

'find the label and update it's text property
 Dim pDoc As IMxDocument
  Dim pGraphicsCont As IGraphicsContainer
  Dim pActive As IActiveView
  
  Dim pElemprops As IElementProperties
  Set pDoc = ThisDocument
  Set pGraphicsCont = pDoc.PageLayout
  Set pActive = pGraphicsCont
  pGraphicsCont.Reset
  Set pElemprops = pGraphicsCont.Next
  
  Dim pTextElement As ITextElement
  Dim pElem As IElement
  Dim pEnv As IEnvelope
  Dim pEnv2 As IEnvelope
    
  Do Until pElemprops Is Nothing
    If TypeOf pElemprops Is ITextElement Then
        Set pTextElement = pElemprops
          If pTextElement.Text Like "XXXXXXX XXXXXXX XXXXXXX*" Then
            Set pElem = pElemprops
            Set pEnv = New Envelope
            pElem.QueryBounds pActive.ScreenDisplay, pEnv
            pTextElement.Text = DocInfo
            pGraphicsCont.UpdateElement pTextElement
            Set pEnv2 = New Envelope
            pElem.QueryBounds pActive.ScreenDisplay, pEnv2
            pEnv.Union pEnv2
            
            pActive.PartialRefresh esriViewGraphics, Nothing, pEnv
                
  
    

            Exit Function
          End If
      End If
    Set pElemprops = pGraphicsCont.Next
  Loop



Thanks,
Josh

Outcomes