Results 1 to 8 of 8
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    combination keyboard shortcuts causes app to crash (VBA - Word 97)

    Hiya

    I have a word template that shows a dialog box(form) for user.
    Standard dlg box with text boxes - data is entered into bookmarks in document.

    Our users being keyboard orientated -
    user tabs through the text boxes.
    However when they use certain combination of keyboard shortcuts-
    Word crashes - with a winword.exe message reference memory error.

    When user uses standard tab key to tab through textboxes & click OK button on form - runs smoothly.

    However word crashes when the following occurs:
    user tabs through textboxes & then uses keys SHIFT TAB - to go back to the previous textbox.
    User then continues to tab to next textbox until completed & click OK button on form -
    then winword.exe application error appears.

    When I debugg code - it crashes on line of code either
    End IF (last end if in sub) &
    end Sub

    I have no idea where to start to debug & resolve.
    Any ideas?
    Do you require further info from me?
    I'm also going to post this item in Word - as there may be an end user who may know solution.
    thanks in advance - Diana

  2. #2
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: combination keyboard shortcuts causes app to crash (VBA - Word 97)

    Hi ya
    I cant attach template as the zipped file is 132K & the max you can have is 100k.
    unless you can suggest an alternative way of getting the template?

    regards Diana

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: combination keyboard shortcuts causes app to crash (VBA - Word 97)

    Diana,

    You could try this:

    Open your template, go to the VB Editor, locate the relevant userform in the project view, rightclick on it and Export it - this should give you the userform alone as a .frm file.

    Then attach the .frm file to a post here (or a zip of the .frm file if the .frm file is larger than 100k).

    Gary

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attachment Part 1

    Thanks Gary - that worked
    PART 1 attachment

    please find zipped attached template part 1
    & on next post zipped attached template part 2.
    Just open up template from part 1
    & import modules & forms from part 2.

    regards Diana
    Attached Files Attached Files

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attachment Part 2

    Thanks Gary - that worked!
    PART 2 attachment

    regards Diana
    Attached Files Attached Files

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: combination keyboard shortcuts causes app to crash (VBA - Word 97)

    Hi Diana,

    I've downloaded the template and reassembled it, but hard to really test it as it's impractical for me to compile the code: there are references set to a couple of libraries, and numerous calls to functions that are either in a global template or have something to do with those missing libraries.

    So, just left to a little bit of guesswork...
    The first thing that jumps out at me is (guided by your description that the error is being flagged at the end of the cmd_OK procedure (by the way, what happens when you compile the code (let alone run it) - do you get a compile error?).

    Anyway, the following just looks a little dodgy:

    <pre> StatusBar = "Resetting for Editing ... "
    Unload Me
    End If
    'Dim docprofileNew As type_DocProfile

    ActiveDocument.Fields.Update
    ActiveWindow.WindowState = wdWindowStateMaximize
    End Sub
    </pre>

    in that you're unloading the userform that contains the currently running code, in mid-procedure. That's likely to cause some kind of jolt! The Unload Me should be the very last statement in this procedure, because once that statement runs, the procedure vaporizes.

    So as first steps, try moving the Unload Me to the end of the procedure and see if that helps.

    Also, if you are getting compile errors (i.e. when you click Debug>Compile FileNote) then you've got errors in the code which need to sorted, before you can release it for live use. (Forgive me if you don't need this latter reminder, it's hard for me to tell 'cause I can't compile the code from here...)

    Gary

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: combination keyboard shortcuts causes app to crash (VBA - Word 97)

    Not to get too far off the subject... I usually use Me.Hide inside the code attached to the OK or Cancel button, and then use Unload in the calling procedure after I've finished extracting all the data. That seems to require the fewest global (public) variables. Does anyone else have other suggestions about how best to deal with userforms?

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: combination keyboard shortcuts causes app to crash (VBA - Word 97)

    HI Gary - thanks for looking into for me.
    I have moved the statement unload me to a different location before I posted to forum & word was still crashing.
    also I have compiled project & its fine.

    Its the 1st time I've used code to test controls on a form.

    What I did was:
    I stored the bookmark name for that object or textbox
    in the objects properies .Tag
    For each object I test to see if bookmark exists
    if bookmark exists - insert data into bookmark in document.

    However for the combo list box - (the attendance type listbox)
    for certain items in list when selected -
    then the textbox next to the combo listbox is shown/hide.

    Word only crashes when user is in attendess textbox &
    press keys SHIF Tab
    to back to textbox (txtOther)
    Word doesnt crash when using SHIF Tab to go back to any other object in form.

    Do you think it may be the code & the show/hide textbox.

    I'm going to re-create the template & the form & use the standard code to write data into boomarks.
    ie check if textbox have value if true then write data to bookmark & see if this makes a difference.
    Will let you know how I go.


    'for each control in form
    For Each ctlTemp In Me.Controls

    'if current control property form is a ComboBox or TextBox - continue
    If (TypeOf ctlTemp Is ComboBox) Or (TypeOf ctlTemp Is TextBox) Then

    'from the current control
    With ctlTemp
    'obtain bookmark name from object property - Tag
    strTag = .Tag
    'obtain textbox value
    strValue = Trim$(.Value)
    End With

    'if bookmark exists - goto
    If ActiveDocument.Bookmarks.Exists(strTag) = True Then
    ActiveDocument.Bookmarks(strTag).Select

    With ActiveDocument.Bookmarks

    'if textbox value is not blank & the bookmark exists - continue
    If strValue <> vbNullString And .Exists(strTag) Then

    'if bookmark is Author set author name
    If strTag = "mAuthor" Then
    'Contact details
    ls_Contact = ""
    If ddlb_contact.ListIndex <> -1 Then
    If ddlb_contact.Column(0) <> "(None)" Then
    iIndex = ddlb_contact.Column(1)
    ls_Contact = staffsigningname(iIndex)
    End If
    End If
    DocPropertyInsert "Contact", ls_Contact

    'set author name
    strValue = ls_Contact
    End If

    'if current control is listbox Attendance type
    If strTag = "mAttendanceType" Then

    'obtain selection from Attendance type listbox
    iArrayItem = cmbAttendanceType.ListIndex

    'set standard Attendance type string
    Select Case iArrayItem
    Case 0 To 1
    strAttendanceType = cmbAttendanceType.Value
    strBookmarkAttendType = "marrItemAttendType" & (iArrayItem)
    blnOtherRequired = False

    Case 2 To 4
    strAttendanceType = arrStrAttendType(iArrayItem)
    strBookmarkAttendType = "marrItemAttendType" & (iArrayItem)
    strAttendanceOther = txtOther.Value
    blnOtherRequired = True
    End Select

    'set variables
    strValue = strAttendanceType
    strTag = strBookmarkAttendType
    End If

    'if string is not empty - insert into document & add bookmark
    If strValue <> "" Then
    Selection.Text = strValue
    ActiveDocument.Bookmarks.Add Name:=strTag
    Selection.Collapse wdCollapseEnd
    End If

    'if attendance type 'other' is required
    'then insert other textbox details into doc - required for rerun dlg purposes
    If (blnOtherRequired = True) Then
    'add bookmark around other instructions
    CCWLib.CCWBookmarkOps.InsertStrAsBookmark strAttendanceOther, "mAttendanceOther"
    Selection.Collapse wdCollapseEnd

    'if attendance other is required - add bookmark
    strBookmarkName = "mAttendanceOther"
    If ActiveDocument.Bookmarks.Exists(strBookmarkName) = True Then
    ActiveDocument.Bookmarks(strBookmarkName).Select
    ActiveDocument.Bookmarks.Add strBookmarkAttendType
    End If

    'set flag
    blnOtherRequired = False
    End If
    End If
    End With
    End If
    End If
    Next ctlTemp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •