Error setting AllowBreakAcrossPage

J

JWS315

I get an error trying to set Row 1 of a 2 row table to keep from breaking
across columns - Not sure what is not correct witht code below? Error is 438
Object does not support this property or method...

Set myRange = wdApp.Selection.Range
Set myTable = wdApp.ActiveDocument.Tables.Add(myRange, 2, 1,
wdWord9TableBehavior, wdAutoFitWindow)
wdApp.ActiveDocument.Tables(wdApp.ActiveDocument.Tables.Count).Rows(1).AllowBreakAcrossPage = False

Jerry
 
D

Doug Robbins - Word MVP

I would think that this line

wdApp.ActiveDocument.Tables(wdApp.ActiveDocument.Tables.Count).Rows

should be

wdApp.ActiveDocument.Tables.Count.Rows etc.



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

JWS315

Doug,

I tried your suggestion, however I still receive the same error. In looking
at Word VBA help it states that the AllowBreakAcrossPage property applies to
a TableStyle object, if this is the case then I would guess that I have the
wrong statement.

Any suggestions on how the code would look would be appreciated, I have
tried several interations but with no luck.

Thanks
Jerry
 
D

Doug Robbins - Word MVP

Turns out you cannot use the .Count property as I suggested. The following
should work however

Dim i As Long
i = wdApp.ActiveDocument.Tables.Count
wdApp.ActiveDocument.Tables(i).Rows(1).AllowBreakAcrossPages = False


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

JWS315

Doug,

The first format of the code I was using is basically the same (I just
replaced i with the assignment) - i still get the same error - Is this
something that cannot be done on a table object? I found in the help that
AllowBreakAcrossPages applies to a Tablestyle object so maybe I am taking the
wrong approach?

Thanks
Jerry
 
D

Doug Robbins - Word MVP

Running a macro with the following code from Word itself, certainly sets
that attribute for the first row in the last table in the active document:

Dim i As Long
i = ActiveDocument.Tables.Count
ActiveDocument.Tables(i).Rows(1).AllowBreakAcrossPages = False

From where are you running this code? Is the table being added to the
document in the first place?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

JWS315

I am running the code from an Access module, the first thing I do is add the
table then I try to set the property. I am able to do other things to the
table via Access however run into a problem when trying to set this property.
The table is a 2 row, 1 column table, nothing real elaborate.

Thanks for your help - Jerry
 
D

Doug Robbins - Word MVP

Can you post the full code from your Access procedure so that I can try the
same thing from Access.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

JWS315

Doung - Here is an abbreviated version of the code I am running:

Option Compare Database

Function rptWord()
Dim wdApp As Object
Dim myRange As Object
Dim myTable As Object
Dim strFilter As String
Dim fName As String
Dim message As String
Dim Response As String
Dim docFinal As Object
Dim tmpFinalDoc As String
Dim wdFname As String

'Display Windows File Save As Dialog
Specifyfilename:
strFilter = ""
strFilter = ahtAddFilterItem(strFilter, "Word Documents (*.doc)", "*.doc")
fName = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, _
FilterIndex:=3, _
OpenFile:=False, _
FullPath:=True, _
Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_HIDEREADONLY, _
DialogTitle:="Specify the folder and file name to save the
Document", _
FileName:="Application.doc")

If fName = "false" Then
Err.Number = 32755
GoTo Err_rptWord
End If
message = "Document will be saved in the following folder: " & vbCrLf &
MyCurDir
Response = MsgBox(message, vbOKCancel, "File Location")
If Response = vbOK Then
wdFname = fName
Else
GoTo Specifyfilename
End If

' Create new hidden instance of Word.
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
Set docFinal = wdApp.Documents.Add
docFinal.PageSetup.Orientation = wdOrientPortrait
docFinal.PageSetup.DifferentFirstPageHeaderFooter = False
docFinal.PageSetup.LeftMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.RightMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.TopMargin = wdApp.InchesToPoints(0.5)
docFinal.PageSetup.BottomMargin = wdApp.InchesToPoints(0.5)
docFinal.SaveAs FileName:="" & wdFname & "", FileFormat:=wdWordDocument

'Activate the current window
tmpFinalDoc = GetFileName(wdFname)
wdApp.Windows(tmpFinalDoc).Activate
Set myRange = wdApp.Selection.Range
Set myTable =
wdApp.ActiveDocument.Tables.Add(myRange, 2, 1, wdWord9TableBehavior,
wdAutoFitFixed)
myTable.Borders(wdBorderLeft).LineStyle =
wdLineStyleNone
myTable.Borders(wdBorderRight).LineStyle =
wdLineStyleNone
myTable.Borders(wdBorderTop).LineStyle =
wdLineStyleNone
myTable.Borders(wdBorderBottom).LineStyle =
wdLineStyleNone
myTable.Borders(wdBorderHorizontal).LineStyle =
wdLineStyleNone
myTable.Borders(wdBorderVertical).LineStyle =
wdLineStyleNone
myTable.Borders(wdBorderDiagonalDown).LineStyle =
wdLineStyleNone
myTable.Borders(wdBorderDiagonalUp).LineStyle =
wdLineStyleNone
myTable.Borders.Shadow = False
myTable.Rows(1).AllowBreakAcrossPage = False

'wdApp.ActiveDocument.Tables(wdApp.ActiveDocument.Tables.Count).Rows.AllowBreakAcrossPage = False
docFinal.SaveAs FileName:="" & wdFname & "", FileFormat:=wdWordDocument
docFinal.Close
wdApp.Quit wdDoNotSaveChanges
Set docFinal = Nothing
Set wdApp = Nothing
Err_rptWord:
End Function
 
D

Doug Robbins - Word MVP

I would suggest that you continue to refer to the document as docFinal and
to the table as myTable and not switch to using ActiveDocument

Set myTable = docFinal.Tables.Add(myRange, 2, 1, wdWord9TableBehavior,
wdAutoFitFixed)

Word may be getting confused by your switching.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

JWS315

Changed as you suggested and used the following:
myTable.Rows(1).AllowBreakAcrossPage = False

Still get a 438 error code on the statement above...

Jerry
 
D

Doug Robbins - Word MVP

myTable.Rows(1).AllowBreakAcrossPage = False

should be:

myTable.Rows(1).AllowBreakAcrossPages = False

Sorry I did not spot that before. But then you did not spot that I was
using:

AllowBreakAcrossPages

instead of

AllowBreakAcrossPage

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top