Andrew Douglas Pitonyak wrote:


Gary Dale wrote:
Sorry if this is pretty basic but I'm trying to print a form letter and I wanted to customize it a little based on the values of the data in the mailing list. If a field contains a value, I add an "attn:" line if I have a name or a title to send to the attention of.

The macro is assigned to the Print Document event, which seems to be correct because it is getting called once per database record - and failing each time with the same error.

Anyway, below is my code - it's failing on the "IF Found THEN" line with a "BASIC runtime error. Incorrect property value" error.

The idea, as I said, is straightforward: search for the word "Dear" which starts the letter, then add an "Attn:" paragraph above it if there is someone it should be directed to. I'm just trying to get the adding of the "Attn:" working with this code. I'll add the fields later if I can get this working. :)

Any hints?


Sub Main
   Dim Doc         As Object     Dim Cursor         As Object
   Dim SearchDesc    As Object

   Doc         = StarDesktop.CurrentComponent
   SearchDesc    = Doc.createSearchDescriptor()
   SearchDesc.searchString            = "Dear"
   SearchDesc.searchCaseSensitive    = True
   SearchDesc.searchWords            = True
   SearchDesc.searchSimilarity        = False
   Found         = Doc.findFirst(SearchDesc)
   IF Found THEN
       Cursor    = Doc.Text.createTextCursor
       IF NOT Doc.Text.isStartOfSentence() THEN
           Doc.Text.gotoStartOfSentence(FALSE)
       END IF
       Cursor.String = "Attn:"
Doc.Text.insertControlCharacter(Cursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False) END IF
   END IF
End Sub

What happens if you run this instead?

Sub Main
  Dim Doc         As Object     Dim Cursor         As Object
  Dim SearchDesc    As Object

  Doc         = StarDesktop.CurrentComponent
  SearchDesc    = Doc.createSearchDescriptor()
  SearchDesc.searchString            = "Dear"
  SearchDesc.searchCaseSensitive    = True
  SearchDesc.searchWords            = True
  SearchDesc.searchSimilarity        = False
  Found         = Doc.findFirst(SearchDesc)
  IF Found THEN
     REM I am a comment so we do nothing
  END IF
End Sub

What happens if you place a line as:

Option Explicit

As one of the first lines in the file (a line by itself before any variables or subroutines are defined)?

I have some more thoughts, but I really need to go to sleep now.

I am interested in what you are doing. I have some comments related to using the standard document Text object, it does not strike me as safe, but I must explain that later.

Commenting out the code in the IF statement had no affect.

Turning on Option Explicit and declaring Found to be Boolean moved the error up to the Found = Doc.findFirst line. This suggests that findFirst is returning something other than a Boolean. The only way I think that could happen is if findFirst isn't a method of Doc - it may be returning a null value.

One thing I'm not clear on in printing a form letter is which file is the current component? How do I distinguish the database row from the text document? Or to put it another way, in the code above, how do I ensure that Doc = StarDesktop.CurrentComponent is actually picking up the text document?


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to