Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 21

Thread: Run-time error '4248': this command is not available because no document is open

  1. #1
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location

    Run-time error '4248': this command is not available because no document is open

    Hello my document is attached. I keep getting this error on Windows XP SP3

    behavior is like this:

    4248 referenced in title block above.

    If I click “End” on the error window, the macros ran. They didn’t work right, though, because the boxes didn’t check.

    If I choose Debug, then the Visual Basic page shows up and highlights the first half-line of the programing.

    Any ideas? Thanks, Midani[vba]Private Sub Document_Open()
    If ActiveDocument.FormFields("text64").Result = "Yes" Then ActiveDocument.FormFields("Check1").CheckBox.Value = True
    If ActiveDocument.FormFields("text64").Result = "No" Then ActiveDocument.FormFields("Check2").CheckBox.Value = True[/vba]
    [vba]
    If ActiveDocument.FormFields("text65").Result = "Inpatient" Then ActiveDocument.FormFields("Check3").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "ER/Outpatient" Then ActiveDocument.FormFields("Check4").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "DOA" Then ActiveDocument.FormFields("Check5").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "Nursing Home" Then ActiveDocument.FormFields("Check6").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "Hospice" Then ActiveDocument.FormFields("Check7").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "Residence" Then ActiveDocument.FormFields("Check8").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "Other (Specify)" Then ActiveDocument.FormFields("Check9").CheckBox.Value = True

    If ActiveDocument.FormFields("text66").Result = "Married" Then ActiveDocument.FormFields("Check10").CheckBox.Value = True
    If ActiveDocument.FormFields("text66").Result = "Never Married" Then ActiveDocument.FormFields("Check11").CheckBox.Value = True
    If ActiveDocument.FormFields("text66").Result = "Widowed" Then ActiveDocument.FormFields("Check12").CheckBox.Value = True
    If ActiveDocument.FormFields("text66").Result = "Divorced" Then ActiveDocument.FormFields("Check13").CheckBox.Value = True
    If ActiveDocument.FormFields("text66").Result = "Unknown" Then ActiveDocument.FormFields("Check14").CheckBox.Value = True

    If ActiveDocument.FormFields("text67").Result = "Yes" Then ActiveDocument.FormFields("Check15").CheckBox.Value = True
    If ActiveDocument.FormFields("text67").Result = "No" Then ActiveDocument.FormFields("Check16").CheckBox.Value = True

    If ActiveDocument.FormFields("text68").Result = "No" Then ActiveDocument.FormFields("Check17").CheckBox.Value = True
    If ActiveDocument.FormFields("text68").Result = "Yes" Then ActiveDocument.FormFields("Check18").CheckBox.Value = True

    If ActiveDocument.FormFields("text69").Result = "Resomation" Then ActiveDocument.FormFields("Check19").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Burial" Then ActiveDocument.FormFields("Check20").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Cremation" Then ActiveDocument.FormFields("Check21").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Removal from State" Then ActiveDocument.FormFields("Check22").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Donation" Then ActiveDocument.FormFields("Check23").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Other (Specify)" Then ActiveDocument.FormFields("Check24").CheckBox.Value = True

    ActiveDocument.FormFields("text64").Result = " "
    ActiveDocument.FormFields("text65").Result = " "
    ActiveDocument.FormFields("text66").Result = " "
    ActiveDocument.FormFields("text67").Result = " "
    ActiveDocument.FormFields("text68").Result = " "
    ActiveDocument.FormFields("text69").Result = " "
    End Sub

    Sub ChangeDocProperties()
    On Error GoTo ErrHandler
    ActiveDocument.BuiltInDocumentProperties("Title") = "DC (Burial)"
    Exit Sub

    ErrHandler:
    If Err <> 0 Then

    'Add a document.
    Documents.Add

    'Clear the error.
    Err.Clear

    'Execute the code that caused the error.
    Resume

    End If
    End Sub
    Sub CountHiddenDocs()
    ' This macro opens an existing document as hidden
    ' then makes the hidden document visible.
    Dim Doc1 As Document

    ' Open MyDoc.Doc document as hidden.
    Set Doc1 = Documents.Open("<Path>\MyDoc.Doc", Visible:=False)

    ' Reset the document object variable to make visible the
    ' hidden document.
    '
    ' NOTE: The following command line will NOT open a
    ' second instance of the hidden document but instead
    ' make the currently open, hidden instance of the
    ' document visible.
    Set Doc1 = Documents.Open("<Path>\MyDoc.Doc", Visible:=True)
    Doc1.ActiveWindow.Activate
    End Sub


    [/vba]

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    We need more information. What module is the code in?

    Document_Open must be in the document itself. Clearly if you are getting that error SOMETHING is not right. Please describe the actual conditions.

    BTW: you should use Select Case rather than multiple IF statements.

    In your code what happens if text65 = Inpatient?

    1. Check3 = true
    2. If statement executes, testing if text65 = ER/Outpatient
    3. If statement executes, testing if text65 = DOA
    4. If statement executes, testing if text65 = Nursing Home
    5. If statement executes, testing if text65 = Hospice
    6. If statement executes, testing if text65 = Residence
    7. If statement executes, testing if text65 = Other (Specify)

    If you use Select Case, what happens if text65 = Inpatient?

    [vba]
    Select Case ActiveDocument.FormFields("text65").Result
    Case "Inpatient"
    ActiveDocument.FormFields("Check3").CheckBox.Value = True
    Case "ER/Outpatient"
    ActiveDocument.FormFields("Check4").CheckBox.Value = True
    Case "DOA"
    ActiveDocument.FormFields("Check5").CheckBox.Value = True
    Case "Nursing Home"
    ActiveDocument.FormFields("Check6").CheckBox.Value = True
    Case "Hospice"
    ActiveDocument.FormFields("Check7").CheckBox.Value = True
    Case "Residence"
    ActiveDocument.FormFields("Check8").CheckBox.Value = True
    End Select[/vba]

    1. Check3 = True

    …and that is it. Nothing else happens. The other conditions are not tested – this is what Select Case is for - testing multiple values of the SAME variable or object.

  3. #3
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location
    Hello this code that I displayed is the code corresponding to the VBA document itself. Would it help if I zipped up the document and sent it to you for your review? I have to say that I am a Java application developer and
    I know very little about VB or much less VBA.

    I am simply trying to overcome that error when the document is opened up on a Microsoft Professional XP SP3 machine.

    There are many other documents like it but I did not code it. I did review everything that Microsoft said on the subject but it was not helpful.

    If you could re-explain what you were saying to me because I am such a newbie. I noted that you produced some code with the Option Explicit but I am not sure what you meant by it.

    Thanks a lot, Midani

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Maybe you need to stat using Help. Especially Option Explicit. Put your cursor on it and press F1.

    Ditto Select Case, although that is a very basic programming concept.

    I will ask again...please describe the exact circumstances. It will also help if you posted your entire code. What is the full code for the procedure with:
    [vba]If ActiveDocument.FormFields("text65").Result = "Inpatient" Then _
    ActiveDocument.FormFields("Check3").CheckBox.Value = True [/vba]

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Maybe you need to stat using Help. Especially Option Explicit. Put your cursor on it and press F1.

    Ditto Select Case, although that is a very basic programming concept.

    I will ask again...please describe the exact circumstances. It will also help if you posted your entire code. What is the full code for the procedure with:
    [vba]If ActiveDocument.FormFields("text65").Result = "Inpatient" Then _
    ActiveDocument.FormFields("Check3").CheckBox.Value = True [/vba]

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Maybe you need to start using Help. Especially Option Explicit. Put your cursor on it and press F1.

    Ditto Select Case, although that is a very basic programming concept.

    I will ask again...please describe the exact circumstances. It will also help if you posted your entire code. What is the full code for the procedure with:
    [vba]If ActiveDocument.FormFields("text65").Result = "Inpatient" Then _
    ActiveDocument.FormFields("Check3").CheckBox.Value = True [/vba]

  7. #7
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location
    The full code for the entire document is here, it is for the General Module and the Open Module.

    I went ahead and put all the events into a notepad for you:

    [VBA]
    Private Sub Document_Close()
    End Sub
    Private Sub Document_ContentControlAfterAdd(ByVal NewContentControl As ContentControl, ByVal InUndoRedo As Boolean)
    End Sub
    Private Sub Document_ContentControlBeforeContentUpdate(ByVal ContentControl As ContentControl, Content As String)
    End Sub
    Private Sub Document_ContentControlBeforeDelete(ByVal OldContentControl As ContentControl, ByVal InUndoRedo As Boolean)
    End Sub
    Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
    End Sub
    Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
    End Sub
    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    End Sub
    Private Sub Document_Open()
    If ActiveDocument.FormFields("text64").Result = "Yes" Then ActiveDocument.FormFields("Check1").CheckBox.Value = True
    If ActiveDocument.FormFields("text64").Result = "No" Then ActiveDocument.FormFields("Check2").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "Inpatient" Then ActiveDocument.FormFields("Check3").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "ER/Outpatient" Then ActiveDocument.FormFields("Check4").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "DOA" Then ActiveDocument.FormFields("Check5").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "Nursing Home" Then ActiveDocument.FormFields("Check6").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "Hospice" Then ActiveDocument.FormFields("Check7").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "Residence" Then ActiveDocument.FormFields("Check8").CheckBox.Value = True
    If ActiveDocument.FormFields("text65").Result = "Other (Specify)" Then ActiveDocument.FormFields("Check9").CheckBox.Value = True
    If ActiveDocument.FormFields("text66").Result = "Married" Then ActiveDocument.FormFields("Check10").CheckBox.Value = True
    If ActiveDocument.FormFields("text66").Result = "Never Married" Then ActiveDocument.FormFields("Check11").CheckBox.Value = True
    If ActiveDocument.FormFields("text66").Result = "Widowed" Then ActiveDocument.FormFields("Check12").CheckBox.Value = True
    If ActiveDocument.FormFields("text66").Result = "Divorced" Then ActiveDocument.FormFields("Check13").CheckBox.Value = True
    If ActiveDocument.FormFields("text66").Result = "Unknown" Then ActiveDocument.FormFields("Check14").CheckBox.Value = True
    If ActiveDocument.FormFields("text67").Result = "Yes" Then ActiveDocument.FormFields("Check15").CheckBox.Value = True
    If ActiveDocument.FormFields("text67").Result = "No" Then ActiveDocument.FormFields("Check16").CheckBox.Value = True
    If ActiveDocument.FormFields("text68").Result = "No" Then ActiveDocument.FormFields("Check17").CheckBox.Value = True
    If ActiveDocument.FormFields("text68").Result = "Yes" Then ActiveDocument.FormFields("Check18").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Resomation" Then ActiveDocument.FormFields("Check19").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Burial" Then ActiveDocument.FormFields("Check20").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Cremation" Then ActiveDocument.FormFields("Check21").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Removal from State" Then ActiveDocument.FormFields("Check22").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Donation" Then ActiveDocument.FormFields("Check23").CheckBox.Value = True
    If ActiveDocument.FormFields("text69").Result = "Other (Specify)" Then ActiveDocument.FormFields("Check24").CheckBox.Value = True
    ActiveDocument.FormFields("text64").Result = " "
    ActiveDocument.FormFields("text65").Result = " "
    ActiveDocument.FormFields("text66").Result = " "
    ActiveDocument.FormFields("text67").Result = " "
    ActiveDocument.FormFields("text68").Result = " "
    ActiveDocument.FormFields("text69").Result = " "
    End Sub
    'Sub ChangeDocProperties()
    ' On Error GoTo ErrHandler
    ' ActiveDocument.BuiltInDocumentProperties("Title") = "DC (Burial)"
    'Exit Sub
    'ErrHandler:
    ' If Err <> 0 Then
    'Add a document.
    ' Documents.Add
    'Clear the error.
    ' Err.Clear
    'Execute the code that caused the error.
    ' Resume
    ' End If
    'End Sub
    'Sub CountHiddenDocs()
    ' This macro opens an existing document as hidden
    ' then makes the hidden document visible.
    ' Dim Doc1 As Document
    ' Open MyDoc.Doc document as hidden.
    ' Set Doc1 = Documents.Open("MyDoc.Doc", Visible:=False)
    ' Reset the document object variable to make visible the
    ' hidden document.
    '
    ' NOTE: The following command line will NOT open a
    ' second instance of the hidden document but instead
    ' make the currently open, hidden instance of the
    ' document visible.
    'Set Doc1 = Documents.Open("<Path>\MyDoc.Doc", Visible:=True)
    'Doc1.ActiveWindow.Activate
    'End Sub

    Private Sub Document_Sync(ByVal SyncEventType As Office.MsoSyncEventType)
    End Sub
    Private Sub Document_XMLAfterInsert(ByVal NewXMLNode As XMLNode, ByVal InUndoRedo As Boolean)
    End Sub
    Private Sub Document_XMLBeforeDelete(ByVal DeletedRange As Range, ByVal OldXMLNode As XMLNode, ByVal InUndoRedo As Boolean)
    End Sub
    [/VBA]

  8. #8
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location
    I changed my code for the Document module:

    [VBA]Private Sub Document_Open()
    If ActiveDocument.FormFields("text64").Result = "Yes" Then ActiveDocument.FormFields("Check1").CheckBox.Value = True
    If ActiveDocument.FormFields("text64").Result = "No" Then ActiveDocument.FormFields("Check2").CheckBox.Value = True
    Select Case ActiveDocument.FormFields("text65").Result
    Case "Inpatient"
    ActiveDocument.FormFields("Check3").CheckBox.Value = True
    Case "ER/Outpatient"
    ActiveDocument.FormFields("Check4").CheckBox.Value = True
    Case "DOA"
    ActiveDocument.FormFields("Check5").CheckBox.Value = True
    Case "Nursing Home"
    ActiveDocument.FormFields("Check6").CheckBox.Value = True
    Case "Hospice"
    ActiveDocument.FormFields("Check7").CheckBox.Value = True
    Case "Residence"
    ActiveDocument.FormFields("Check8").CheckBox.Value = True
    Case "Other"
    ActiveDocument.FormFields("Check9").CheckBox.Value = True
    End Select
    Select Case ActiveDocument.FormFields("text66").Result
    Case "Married"
    ActiveDocument.FormFields("Check10").CheckBox.Value = True
    Case "Never Married"
    ActiveDocument.FormFields("Check11").CheckBox.Value = True
    Case "Widowed"
    ActiveDocument.FormFields("Check12").CheckBox.Value = True
    Case "Divorced"
    ActiveDocument.FormFields("Check13").CheckBox.Value = True
    Case "Unknown"
    ActiveDocument.FormFields("Check14").CheckBox.Value = True
    End Select
    Select Case ActiveDocument.FormFields("text67").Result
    Case "Yes"
    ActiveDocument.FormFields("Check15").CheckBox.Value = True
    Case "No"
    ActiveDocument.FormFields("Check16").CheckBox.Value = True
    End Select

    Select Case ActiveDocument.FormFields("text68").Result
    Case "No"
    ActiveDocument.FormFields("Check17").CheckBox.Value = True
    Case "Yes"
    ActiveDocument.FormFields("Check18").CheckBox.Value = True
    End Select

    Select Case ActiveDocument.FormFields("text69").Result
    Case "Resomation"
    ActiveDocument.FormFields("Check19").CheckBox.Value = True
    Case "Burial"
    ActiveDocument.FormFields("Check20").CheckBox.Value = True
    Case "Cremation"
    ActiveDocument.FormFields("Check21").CheckBox.Value = True
    Case "Removal from State"
    ActiveDocument.FormFields("Check22").CheckBox.Value = True
    Case "Donation"
    ActiveDocument.FormFields("Check23").CheckBox.Value = True
    Case "Other (Specify)"
    ActiveDocument.FormFields("Check24").CheckBox.Value = True
    End Select
    ActiveDocument.FormFields("text64").Result = " "
    ActiveDocument.FormFields("text65").Result = " "
    ActiveDocument.FormFields("text66").Result = " "
    ActiveDocument.FormFields("text67").Result = " "
    ActiveDocument.FormFields("text68").Result = " "
    ActiveDocument.FormFields("text69").Result = " "
    End Sub[/VBA]

  9. #9
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location
    Here is the document.

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    When I open that document I do not get the error you say you get.

    I can not check if the the results are correct as you do not use explicit naming...and I sure am not going to go through the entire document trying to find which formfield is "text65", or even which checkbox is Check1,

  11. #11
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location
    Ok thanks and sorry to be so frustrating.

    You asked earlier:

    In your code what happens if text65 = Inpatient?

    Then the box gets checked that says : Inpatient.

    I am checking on the meaning of the other fields you mention.

    Do you have any suggestions on how to Explicitly name those other fields, could you provide an example perhaps? Thanks, Midani

  12. #12
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location
    I found out that there are six (6) fields on the bottom of the form that relate to the following:
    64 Case Military
    65 Case Place of Death
    66 Case Marital Status
    67 Case Resident City Limits
    68 Case Hispanic Origin
    69 Case Dispositions

    The way that it is supposed to work is that there is a parameter from XML which gets passed to the form from those six (6) fields which tells the form which checkboxes get checked. After it executes this, it also disappears from view.

  13. #13
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "The way that it is supposed to work is that there is a parameter from XML which gets passed to the form from those six (6) fields which tells the form which checkboxes get checked. After it executes this, it also disappears from view."

    What this got to do with your original posted question?

    Run-time error '4248': this command is not available because no document is open

    Explicitly named controls (the formfields) means just that. The formfield is NAMED somethng meaningful. The name is set in the Properties dialog.

    For example (and yes I could go through the document trying to find the right one), you have text64 make Check1 checked or unchecked. BUT, which one is it? I do not even know - and I have been looking for 5 minutes -which formfield is text64.

  14. #14
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location

    Answer

    It is in the lower left corner in a table by itself of the form, below the actual form itself, it is hidden.

    Thanks,
    Midani

  15. #15
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    That was just an example. I do not actually care where it is. The point is that text64 does not MEAN anything. The name is meaningless, it does not give any information about where it is, nor any meaningful/logical connection to Check1 (which is where exactly). In other words, I have NO easy way of verifying that the value of text64 is in fact making the correct value in the checkbox - as I do not have any easy way of finding them.

    But back to why you posted. There is no error 4248. So what exactly is your problem?

  16. #16
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    I looking at the code for some time. (whoever set this up should really look into object naming standards.)

    Error 4248 is self explanatory, but I'm wondering it this occurs after a new document is added with the Sub ChangeDocProperties?

    Can you describe the steps to using this document? How do the formfields at the bottom get updated?
    Last edited by Tinbendr; 04-11-2012 at 11:27 AM.

    David


  17. #17
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location

    Answer Regarding The Uses of this document

    Hello I am so glad you commented, VBA is out of my realm and I need so much help on this one.

    What happens is that there is a little table on the lower left hand side of the page, and what happens is that there are six (6) values that get passed to the document from a sister document in xml (words) and these words would execute checkboxes ordinarily. These are fields 64-69.

    The word which passes as field 64 to the form informs the checkboxes to be checked.

    EXAMPLE: If the person did military service under item 6 of the form, field name 64 could have two cases a yes or a no, and a yes would pass to the form and also check the box for yes or no. (It is this way with the rest, 65, 66, 67, 68 and 69. These cases pass to the form as an object in xml, a value that is retained in an dynamic web application.)

    Honestly I could not see any examples of this on the internet, so it makes it particularly a difficult situation.

    -----------------------------------------------------------------------------------------

    I am also attaching a different version of the document.

    Many Thanks, Midani
    Attached Files Attached Files

  18. #18
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    Quote Originally Posted by midani
    What happens is that there is a little table on the lower left hand side of the page,...
    A Word document?

    David


  19. #19
    VBAX Regular
    Joined
    Apr 2012
    Posts
    10
    Location
    nope if you pull up that document I posted in the last post, you will see the tiny little table on the bottom left of the document.

  20. #20
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    The reason you're getting that error (collection does not exist) is that the formfield has been deleted, probably [FONT='Calibri','sans-serif']accidentally[/FONT]. Now the code is try to access something that isn't there.

    You'll have to replace that file with the original. (Maybe from your email?)

    David


Posting Permissions

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