PDA

View Full Version : Deleting multiple different bookmarks from one selection



cfbrian
06-18-2006, 03:21 PM
Hi all
In one of the drop down list I have created in an input form, I have the following selection:
-Vanilla ice cream,
-Vanilla ice cream with toppings,
-Vanilla & cholocate ice cream,
-Vanilla & chocolate ice cream with toppings,
-Chocolate icecream,
-Chocolate ice cream with with toppings.

In another list are checkbox with toppings:
- M&M
- Chocolate sprinkles
- Mixed nuts
- Raisins
- Orioles

On the form is a command click button and after making the selections, a click would start to delete the unwanted paragraphs (ice cream flavours & toppings not selected). The paragraph are details on how to prepare the icecream and info about the toppings . The document is structured as such: Chocolate paragraph is bookmarked choc, vanilla bookmarked vanilla, chocolate sprinkles as choc_sprinkles etc etc. (Bookmarks are created using Insert>Bookmarks)
One can select multiple topping options to the one main ice cream selection e.g. Vanilla with toppings can have all toppings or just two. But if I were to select the vanilla ice cream only option, only the passage of vanilla would remain in the document, without any descriptions on the toppings.

I have created the input form and command button but does not seem to get the code to do what I intended. Please help :bow:

Thanks a million

fumei
06-18-2006, 04:43 PM
I have created the input form and command button but does not seem to get the code to do what I intended.Then post your code please. Let's see what you have going on.

cfbrian
06-18-2006, 05:07 PM
I have attached the code I have thus far ...... I think I have attached using the editor mode. If not apologies.


'Unprotect Document
Selection.GoTo What:=wdGoToBookmark, Name:="Start"
If WordBasic.DocumentProtection() = 1 Then
WordBasic.ToolsUnprotectDocument DocumentPassword:=""
End If

If IceCreamSelection <> "" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Vanilla"
If WordBasic.[GetFormResult$]("Flavors") = "Vanilla Ice Cream" Then
Selection.Text = "Vanilla"
End If

If WordBasic.[GetFormResult$]("Flavors") = "Vanilla Ice Cream with Toppings" Then
Selection.Text = "VanillaToppings"
End If
If WordBasic.[GetFormResult$]("Flavors") = "Vanilla & cholocate ice cream" Then
Selection.Text = "VanillaChoc"
End If
If WordBasic.[GetFormResult$]("Flavors") = "Vanilla & Chocolate Ice Cream with Toppings" Then
Selection.Text = "VanChocToppings"
End If
If WordBasic.[GetFormResult$]("Flavors") = "Chocolate Ice Cream" Then
Selection.Text = "Chocolate"
End If
If WordBasic.[GetFormResult$]("Flavors") = "Chocolate with Toppings" Then
Selection.Text = "ChocToppings"
End If


'OPTIONS
'Vanilla Flavor Only
If WordBasic.[GetFormResult$]("Flavors") = "Vanilla" Then
'Delete for options
MyArray = Array("M&M", "Chocolate sprinkles", "Mixed nuts", _ "Raisins", "Orioles")
DeleteText
GoTo What:=wdGoToBookmark, Name:="App_Gen2"
End If

fumei
06-18-2006, 11:07 PM
1. Could you please use the underscore character to break up your code lines? If they are too long it cause the VBA code windwo here to scroll left/right as well as up/down. It is a real pain. Would appreiate it.

For example: If WordBasic.[GetFormResult$]("Flavors") = _
"Vanilla & Chocolate Ice Cream with Toppings" Then
Selection.Text = "VanChocToppings"

2. What version of Word are you using???????? I notice "WordBasic". This can be very important.

3. You are using the Selection object. This can probably be done better. In fact you should be be going to the Selection at all. Designed well there will be no need.

4. You are using multiple If...Then statements. Example
If WordBasic.[GetFormResult$]("Flavors") = yadda yadda Then

If WordBasic.[GetFormResult$]("Flavors") = yadda yadda yadda Then

If WordBasic.[GetFormResult$]("Flavors") = yoda yoda Then.

It would be better to use a Select Case, as in:
Select Case WordBasic.[GetFormResult$]("Flavors")
Case "Vanilla Ice Cream"
* do this *
Case "Vanilla Ice Cream with Toppings"
* do this other stuff *
Case "Vanilla & cholocate ice cream"
* do even other syuff *
etc etc
End SelectIf you have ONE source but multiple possible action, Select Case is better. Why?

If yadda yadda Then yadda yadda End If
If yadda yadda Then yadda yadda End If
If yadda yadda Then yadda yadda End If
If yadda yadda Then yadda yadda End If
If yadda yadda Then yadda yadda End If

Five instructions, right? Your code MUST fire and test all five conditions.

Select Case yadda yadda
Case first condition
do this
Case second condition
do that
Case third condition
End Select

Using Select case will direct the process flow to the condition that is True. In your case - what is the True condition of WordBasic.[GetFormResult$]("Flavors"). Only that one will action. As soon as it finds a True statement it actions it and ignores all the others.

In your code: If WordBasic.[GetFormResult$]("Flavors") = "Vanilla Ice Cream" Then
Selection.Text = "Vanilla"
End If This is yor first If...Then statement. Suppose it is the true one. It is "Vanilla". So the code runs and Selection.Text = "Vanilla". However...ALL your other If...Then statement will also run anyway. They are independent logic statements. Using Select Case brings them all into essentially ONE logic statement.

BTW: Select Case statements can be nested into other Select Case statements.