Need Help With Run-Time Errors

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Montana DOJ Help Desk (NoEmailReplies_at_Please.com)
Date: 10/12/04

  • Next message: George: "How to differentiate between linked/embedded objects?"
    Date: Mon, 11 Oct 2004 22:54:47 -0600
    
    

    Word 2000

    I have the following code (Note the RecordNumber is alphanumeric, so it's
    declared as a string).

    ***************
    Option Base 1
    Option Explicit

    Dim BookmarkName As String
    Dim cbMRI As String
    Dim EndPos As Long
    Dim MRITag As String
    Dim RecordNumber As String
    Dim RecordType As String
    Dim StartPos As Long
    Dim Subroutine As String

    Sub PasteLocate()

        Dim RangeEnd As Long
        Dim RangeStart As Long
        Dim RecordNumberRange As Range

        On Error GoTo ErrorHandler

    ' Checks for the existance of the required bookmarks and document variables.
        CheckRequiredBookmarks

    ' Pastes the Locate into the document.
        Selection.EndKey Unit:=wdStory
        Selection.Paste

    ' Bookmarks the record in the document using the MIN or NIC as part of the
    bookmark name.
        Selection.GoTo what:=wdGoToBookmark, Name:="StartOfRecord"
        Selection.Extend
        Selection.EndKey Unit:=wdStory
        BookmarkName = "Record" & RecordNumber
        ActiveDocument.Bookmarks("\Sel").Copy BookmarkName

    ' Finds the MIN or NIC in the selected text, creates a range covering that
    location, and
    ' bookmarks the range using the MIN or NIC as part of the bookmark name.
        StartPos = InStr(1, Selection.Text, Chr(13) & RecordType & "/",
    vbTextCompare) + 4
        RangeStart = Selection.Start + StartPos
        RangeEnd = RangeStart + RecordNumberLength
    >>> Set RecordNumberRange = ActiveDocument.Range(Start:=RangeStart,
    End:=RangeEnd) ' <<< 4608 Value out of range.
        BookmarkName = RecordType & RecordNumber
    >>> ActiveDocument.Bookmarks.Add Name:=BookmarkName,
    Range:=RecordNumberRange ' <<< 4218 Type mismatch

    ' Finds the MRI in the selected text, creates a range covering that
    location, and
    ' bookmarks the range using the MRI as part of the bookmark name.
        StartPos = InStr(1, Selection.Text, MRITag, vbTextCompare) + 3
        RangeStart = Selection.Start + StartPos
        EndPos = InStr(StartPos + 1, Selection.Text, " ", vbTextCompare) - 1
        RangeEnd = Selection.Start + EndPos
    >>> Set RecordNumberRange = ActiveDocument.Range(Start:=RangeStart,
    End:=RangeEnd) ' <<< 4608 Value out of range.
        BookmarkName = "MRI" & cbMRI
    >>> ActiveDocument.Bookmarks.Add Name:=BookmarkName,
    Range:=RecordNumberRange ' <<< 4218 Type mismatch

    ' Collapses the selection, inserts a paragraph, and redefines the
    StartOfRecord bookmark.
        Selection.Collapse Direction:=wdCollapseEnd
        Selection.TypeParagraph
        ActiveDocument.Bookmarks("\StartOfSel").Copy "StartOfRecord"
        BottomOfDocument = True

    Exit Sub

    ErrorHandler:

        If PreviousError = False Then
            Subroutine = "PasteLocate"
            ErrorTrapping
        End If
        Resume Next

    End Sub
    ***************

    The lines marked with ">>>" are causing run-time errors (The specific error
    is noted at the end of each line). I figure that all of these errors are
    being caused by the same problem, so if I can figure out what's causing the
    first 4608 error, all the errors should be solved. I have confirmed that
    none of the variables being declared at the module level are getting
    re-declared, so by the time this routine is called, the data types are still
    as shown above.

    Here is a sample of the data.

    $L..MT0251111.

    $.L.

    MT0251111

    LOCATE NOTIFICATION AT 1726 EDT 20040827

    1N017TT71MRI1078365.LSS.MT025135Y.NIC/S770194575.0CA/TESTJV.20040827.465115

    61

    LOCATING ORI IS DOJ INFORMATION TECHNOLOGY SERVICES DIVISION

    MKE/LOCATED SECURITIES/RANSOM MONEY

    ORI/MT0251111 TYP/M0 DEN/BLANK ISS/WESTERN UNI0N

    OWN/SMITH,J0HN SDT/BLANK DOT/20040827

    OCA/TESTJV 20040827 MT025135Y 46511561

    VLD/20040827

    MIS/TEST REC0RD

    NIC/S770194575 DTE/20040827 1725 EDT

    SER/20040827111-20040827119

    20040827 MT025135Y 46511561

    MRI 1078369 IN: NC21 1329 AT 27AUG2004 15:26:55 OUT: JLET00 423 AT 27AUG200

    4 15:26:55

    The code should create the following bookmarks:

    1) RecordS770194575 Range covering the entire record
    2) NICS770194575 Range covering just the NIC number
    3) MRI1078369 Range covering the MRI number

    Can anyone see what is causing the run-time errors in this routine?

    -- Tom

    State of Montana
    Department of Justice Help Desk

    "Making the world a safer place."


  • Next message: George: "How to differentiate between linked/embedded objects?"

    Relevant Pages