PDA

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



midani
04-04-2012, 01:45 PM
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, MidaniPrivate 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("<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

fumei
04-04-2012, 02:57 PM
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?


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

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.

midani
04-05-2012, 02:51 PM
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

fumei
04-05-2012, 04:18 PM
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:
If ActiveDocument.FormFields("text65").Result = "Inpatient" Then _
ActiveDocument.FormFields("Check3").CheckBox.Value = True

fumei
04-05-2012, 04:18 PM
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:
If ActiveDocument.FormFields("text65").Result = "Inpatient" Then _
ActiveDocument.FormFields("Check3").CheckBox.Value = True

fumei
04-05-2012, 04:18 PM
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:
If ActiveDocument.FormFields("text65").Result = "Inpatient" Then _
ActiveDocument.FormFields("Check3").CheckBox.Value = True

midani
04-09-2012, 07:08 AM
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:


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

midani
04-09-2012, 07:24 AM
I changed my code for the Document module:

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

midani
04-09-2012, 08:02 AM
Here is the document.

fumei
04-09-2012, 11:23 AM
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,

midani
04-09-2012, 12:21 PM
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

midani
04-09-2012, 12:51 PM
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.

fumei
04-09-2012, 02:39 PM
"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.

midani
04-10-2012, 06:41 AM
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

fumei
04-10-2012, 10:17 AM
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?

Tinbendr
04-11-2012, 11:12 AM
I looking at the code for some time. (whoever set this up should really look into object naming standards.)

Error 4248 (http://support.microsoft.com/kb/209160)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?

midani
04-11-2012, 11:28 AM
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

Tinbendr
04-11-2012, 11:32 AM
What happens is that there is a little table on the lower left hand side of the page,...A Word document?

midani
04-11-2012, 11:36 AM
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.

Tinbendr
04-11-2012, 11:41 AM
The reason you're getting that error (collection does not exist) is that the formfield has been deleted, probably accidentally. 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?)

Tinbendr
04-11-2012, 11:42 AM
you will see the tiny little table on the bottom left of the document.
That's what I'm asking about. How does that table get updated?