P
pkruti
I am trying to create a word document using VB6 and need to use columns
breaks but cant seem to find out why my code doesnt work the way it
should. It creates a column break but when i trying to go back to one
column to finish off the document it takes the second column and puts
it on the next page. Any ideas on what i may be doing wrong with the
code below?
With surveyApp.Selection
surveyApp.ActiveDocument.Range(Start:=.Start,
End:=.Start).InsertBreak
Type:=wdSectionBreakContinuous
..Start = .Start + 1
With surveyApp.ActiveDocument.Range(Start:=.Start,
End:=surveyApp.ActiveDocument.Content.End).PageSetup.TextColumns
..SetCount numcolumns:=2
..EvenlySpaced = True
..LineBetween = False
..Width = InchesToPoints(2.75)
..Spacing = InchesToPoints(0.5)
End With
Dim rs3 As New ADODB.Recordset
Dim rs4 As New ADODB.Recordset
Dim cmd As New ADODB.Command
cmd.ActiveConnection = conn
rs3.Open "SELECT * FROM groupname", conn, adOpenDynamic,
adLockOptimistic
If rs3.EOF Then
.TypeText Text:="None indicated"
.TypeParagraph
.TypeParagraph
rs3.Close
Else
'Setup for mutliple columns
Dim currentline As Integer
Dim group(500) As Integer 'this is the line that the group starts
on
Dim currentgroup As Integer
Dim lines(500) As Integer 'this is the current group for a given
line
currentline = 0
currentgroup = 0
While Not rs3.EOF
currentgroup = currentgroup + 1
group(currentgroup) = currentline
lines(currentline) = currentgroup
.TypeText Text:=rs3("groupname")
.TypeText vbTab
.TypeText Text:=rs3("problem")
.TypeParagraph
currentline = currentline + 1
rs4.Open "SELECT * From problemoccurred WHERE groupname = '" &
rs3!GroupName & "' order by problemoccurred desc", conn, adOpenDynamic,
adLockOptimistic
While Not rs4.EOF
.TypeText Text:=rs4("problemdesc")
lines(currentline) = currentgroup
.TypeText vbTab
.TypeText Text:=rs4("problemoccurred")
.TypeParagraph
currentline = currentline + 1
' .MoveRight unit:=wdCell
' .MoveRight unit:=wdCell
rs4.MoveNext
Wend
rs4.Close
rs3.MoveNext
Wend
rs3.Close
If currentgroup > 1 Then
Dim gobackto As Integer
If lines(currentline / 2) = 1 Then
gobackto = group(2)
Else
gobackto = group(lines(currentline / 2))
End If
.MoveUp unit:=wdLine, Count:=(currentline - gobackto)
.InsertBreak wdColumnBreak
End If
..EndKey wdStory
With surveyApp.ActiveDocument.Range(Start:=.Start,
End:=.End).PageSetup.TextColumns
..SetCount numcolumns:=1
..EvenlySpaced = True
..LineBetween = False
End With
End If
End With
breaks but cant seem to find out why my code doesnt work the way it
should. It creates a column break but when i trying to go back to one
column to finish off the document it takes the second column and puts
it on the next page. Any ideas on what i may be doing wrong with the
code below?
With surveyApp.Selection
surveyApp.ActiveDocument.Range(Start:=.Start,
End:=.Start).InsertBreak
Type:=wdSectionBreakContinuous
..Start = .Start + 1
With surveyApp.ActiveDocument.Range(Start:=.Start,
End:=surveyApp.ActiveDocument.Content.End).PageSetup.TextColumns
..SetCount numcolumns:=2
..EvenlySpaced = True
..LineBetween = False
..Width = InchesToPoints(2.75)
..Spacing = InchesToPoints(0.5)
End With
Dim rs3 As New ADODB.Recordset
Dim rs4 As New ADODB.Recordset
Dim cmd As New ADODB.Command
cmd.ActiveConnection = conn
rs3.Open "SELECT * FROM groupname", conn, adOpenDynamic,
adLockOptimistic
If rs3.EOF Then
.TypeText Text:="None indicated"
.TypeParagraph
.TypeParagraph
rs3.Close
Else
'Setup for mutliple columns
Dim currentline As Integer
Dim group(500) As Integer 'this is the line that the group starts
on
Dim currentgroup As Integer
Dim lines(500) As Integer 'this is the current group for a given
line
currentline = 0
currentgroup = 0
While Not rs3.EOF
currentgroup = currentgroup + 1
group(currentgroup) = currentline
lines(currentline) = currentgroup
.TypeText Text:=rs3("groupname")
.TypeText vbTab
.TypeText Text:=rs3("problem")
.TypeParagraph
currentline = currentline + 1
rs4.Open "SELECT * From problemoccurred WHERE groupname = '" &
rs3!GroupName & "' order by problemoccurred desc", conn, adOpenDynamic,
adLockOptimistic
While Not rs4.EOF
.TypeText Text:=rs4("problemdesc")
lines(currentline) = currentgroup
.TypeText vbTab
.TypeText Text:=rs4("problemoccurred")
.TypeParagraph
currentline = currentline + 1
' .MoveRight unit:=wdCell
' .MoveRight unit:=wdCell
rs4.MoveNext
Wend
rs4.Close
rs3.MoveNext
Wend
rs3.Close
If currentgroup > 1 Then
Dim gobackto As Integer
If lines(currentline / 2) = 1 Then
gobackto = group(2)
Else
gobackto = group(lines(currentline / 2))
End If
.MoveUp unit:=wdLine, Count:=(currentline - gobackto)
.InsertBreak wdColumnBreak
End If
..EndKey wdStory
With surveyApp.ActiveDocument.Range(Start:=.Start,
End:=.End).PageSetup.TextColumns
..SetCount numcolumns:=1
..EvenlySpaced = True
..LineBetween = False
End With
End If
End With