PDA

View Full Version : Solved: Forms and Case Select



ABrown
07-07-2008, 06:52 AM
Hi - I need to take control of the Insert Break form to ensure that when users insert a section break it does not have different first page selected. I can have loaded the form with PgBreak = True so that the PgBreak Option button is selected and then run the following Case Select statement when they click ok - problem is it isn't working...... Can anyone see where I may be going wrong, or a better way that I may approach. The form I have created replicates the Word built-in command and this is the code:

Private Sub Cancel_Click()
Unload Break
End Sub

Private Sub ok_Click()
PgBreak = True
Select Case PgBreak
Case ColBreak = True
Selection.InsertBreak Type:=wdColumnBreak
Unload Break
Case TxtWrapBreak = True
Selection.InsertBreak Type:=wdTextWrappingBreak
Unload Break
Case NextPage = True
Selection.InsertBreak Type:=wdSectionBreakNextPage
Unload Break
Case Continuous = True
Selection.InsertBreak Type:=wdSectionBreakContinuous
Unload Break
Case EvenPage = True
Selection.InsertBreak Type:=wdSectionBreakEvenPage
Unload Break
Case OddPage = True
Selection.InsertBreak Type:=wdSectionBreakOddPage
Unload Break
Case Else
Selection.InsertBreak Type:=wdPageBreak
Unload Break
End Select
End Sub


Many thanks if you can help.

Regards.

Annette:dunno

ABrown
07-08-2008, 02:21 AM
I have since tried with an ElseIf statement and all that happens is it runs the first if and nothing else whichever option I select!! This is the code:
Private Sub OK_Click()
If PgBreak.Enabled = True Then
Selection.InsertBreak Type:=wdPageBreak

ElseIf ColBreak.Enabled = True Then
Selection.InsertBreak Type:=wdColumnBreak
ElseIf TxtWrapBreak.Enabled = True Then
Selection.InsertBreak Type:=wdTextWrappingBreak
ElseIf NextPage.Enabled = True Then
Selection.InsertBreak Type:=wdSectionBreakNextPage
With Selection.PageSetup
.DifferentFirstPageHeaderFooter = False
End With
ElseIf Continuous.Enabled = True Then
Selection.InsertBreak Type:=wdSectionBreakContinuous
ElseIf EvenPage.Enabled = True Then
Selection.InsertBreak Type:=wdSectionBreakEvenPage
ElseIf OddPage.Enabled = True Then
MsgBox ("OddPage")
Selection.InsertBreak Type:=wdSectionBreakOddPage
End If
Unload Break
End Sub

I Never get to the message box OddPage but can't see where it is falling down!!

Any help gratefully received!!

Annette:banghead:

ABrown
07-08-2008, 02:29 AM
All resolved .... I was using Enable instead of Value!! Thanks. Annette:clap:

fumei
07-08-2008, 10:07 AM
It does not look like you are using Option Explicit. I would strongly suggest that you do.

Not sure how you have the userform set up, but you were not using Select Case correctly.

PgBreak = True
Select Case PgBreak
Case ColBreak = True

1. you are setting PgBreak = True

2. Select Case test the value of the given parameter, in this case, PgBreak.

So

Case ColBreak = True

is, in essense, meaningless. The select case is testing value of PgBreak.

Generally - but it depends on the logic required - Select Case is better than ElseIf statements.

ABrown
07-09-2008, 12:25 AM
Thanks Gerry !! I am going to try and do it with Select Case instead - I can see where I was going wrong before. Many thanks for your continued help with my VB problems!! Think I will be a "newbie" for ever! Regards. Annette

fumei
07-09-2008, 10:44 AM
"Think I will be a "newbie" for ever!"

No, I don't think so. We were all newbies at one point, all of us. It takes time and persistence. You will get there. Just keep at it.