Activex Control in Word Document

O

Owen

I am using an activex control (combobox) in a macro that exists within my
word document. I have attached my code below.

The problem is that even when the combobox selection is NOT equal to CLAY,
the macro still executes the code as if the combobox selection was CLAY.

Prehaps the "if result =" method is not valid here?

Appreciate any help you can offer.

Sub test()
Dim CB26 As Object
Set CB26 = ActiveDocument.ComboBox26
With CB26
If Result = CLAY Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
End If
End With
End Sub
 
M

macropod

Hi Owen,

Try something along the lines of:
Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub
 
O

Owen

Hi Macropod

Thanks for the response. You have solved my initial problem. I now have
encountered another problem when trying to extend my code. I have pasted the
code below. The problem occurs at the first line in the debugger, where i
have used the AND and OR statements. I get a message saying "Type Mismatch".

Any thoughts here?

Thanks again for your time.

Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox11.Text = "calcareous" Or "carbonate" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Slightly cemented" Or "Moderately cemented"
Or "Well cemented" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Very weak" Or "Weak" Or "Moderately weak" Or
"Moderately strong" Or "Strong" Or "Very strong" Or "Extremely strong" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End If
End If
End If
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

macropod said:
Hi Owen,

Try something along the lines of:
Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


Owen said:
I am using an activex control (combobox) in a macro that exists within my
word document. I have attached my code below.

The problem is that even when the combobox selection is NOT equal to CLAY,
the macro still executes the code as if the combobox selection was CLAY.

Prehaps the "if result =" method is not valid here?

Appreciate any help you can offer.

Sub test()
Dim CB26 As Object
Set CB26 = ActiveDocument.ComboBox26
With CB26
If Result = CLAY Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
End If
End With
End Sub
 
D

Doug Robbins - Word MVP

Try

If ActiveDocument.ComboBox26.Text = "CLAY" Then
Select Case ActiveDocument.ComboBox1.Text
Case "calcareous" Or "carbonate"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Case "Slightly cemented" Or "Moderately cemented" Or "Well cemented"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Case "Very weak" Or "Weak" Or "Moderately weak" Or "Moderately
strong" _
Or "Strong" Or "Very strong" Or "Extremely strong"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Case Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End Select
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With

I think that your logic might need a bit of work. What about the case where
ComboBox26.Text <> "CLAY"

--
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, originally posted via msnews.microsoft.com
Owen said:
Hi Macropod

Thanks for the response. You have solved my initial problem. I now have
encountered another problem when trying to extend my code. I have pasted
the
code below. The problem occurs at the first line in the debugger, where i
have used the AND and OR statements. I get a message saying "Type
Mismatch".

Any thoughts here?

Thanks again for your time.

Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox11.Text = "calcareous" Or "carbonate" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Slightly cemented" Or "Moderately
cemented"
Or "Well cemented" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Very weak" Or "Weak" Or "Moderately weak"
Or
"Moderately strong" Or "Strong" Or "Very strong" Or "Extremely strong"
Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End If
End If
End If
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

macropod said:
Hi Owen,

Try something along the lines of:
Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


Owen said:
I am using an activex control (combobox) in a macro that exists within
my
word document. I have attached my code below.

The problem is that even when the combobox selection is NOT equal to
CLAY,
the macro still executes the code as if the combobox selection was
CLAY.

Prehaps the "if result =" method is not valid here?

Appreciate any help you can offer.

Sub test()
Dim CB26 As Object
Set CB26 = ActiveDocument.ComboBox26
With CB26
If Result = CLAY Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
End If
End With
End Sub
 
O

Owen

Hi Doug

I am going to read further into the Select Case function.

Initially though, i can't understand how the function would determine if
"calcareous" or "carbonate" are selected since nowhere is ComboBox11 (which
contains those values) referenced in the code you provided.

I'll do some more research on this function, but let me know if i am missing
something simple here.

Thanks again

Doug Robbins - Word MVP said:
Try

If ActiveDocument.ComboBox26.Text = "CLAY" Then
Select Case ActiveDocument.ComboBox1.Text
Case "calcareous" Or "carbonate"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Case "Slightly cemented" Or "Moderately cemented" Or "Well cemented"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Case "Very weak" Or "Weak" Or "Moderately weak" Or "Moderately
strong" _
Or "Strong" Or "Very strong" Or "Extremely strong"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Case Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End Select
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With

I think that your logic might need a bit of work. What about the case where
ComboBox26.Text <> "CLAY"

--
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, originally posted via msnews.microsoft.com
Owen said:
Hi Macropod

Thanks for the response. You have solved my initial problem. I now have
encountered another problem when trying to extend my code. I have pasted
the
code below. The problem occurs at the first line in the debugger, where i
have used the AND and OR statements. I get a message saying "Type
Mismatch".

Any thoughts here?

Thanks again for your time.

Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox11.Text = "calcareous" Or "carbonate" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Slightly cemented" Or "Moderately
cemented"
Or "Well cemented" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Very weak" Or "Weak" Or "Moderately weak"
Or
"Moderately strong" Or "Strong" Or "Very strong" Or "Extremely strong"
Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End If
End If
End If
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

macropod said:
Hi Owen,

Try something along the lines of:
Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


I am using an activex control (combobox) in a macro that exists within
my
word document. I have attached my code below.

The problem is that even when the combobox selection is NOT equal to
CLAY,
the macro still executes the code as if the combobox selection was
CLAY.

Prehaps the "if result =" method is not valid here?

Appreciate any help you can offer.

Sub test()
Dim CB26 As Object
Set CB26 = ActiveDocument.ComboBox26
With CB26
If Result = CLAY Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
End If
End With
End Sub
 
O

Owen

Sorry, ignore my last post...i see the reference to ComboBox1 now.

Time for a break, too many hours looking at the screen here.

Again, thanks for your help.

Owen said:
Hi Doug

I am going to read further into the Select Case function.

Initially though, i can't understand how the function would determine if
"calcareous" or "carbonate" are selected since nowhere is ComboBox11 (which
contains those values) referenced in the code you provided.

I'll do some more research on this function, but let me know if i am missing
something simple here.

Thanks again

Doug Robbins - Word MVP said:
Try

If ActiveDocument.ComboBox26.Text = "CLAY" Then
Select Case ActiveDocument.ComboBox1.Text
Case "calcareous" Or "carbonate"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Case "Slightly cemented" Or "Moderately cemented" Or "Well cemented"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Case "Very weak" Or "Weak" Or "Moderately weak" Or "Moderately
strong" _
Or "Strong" Or "Very strong" Or "Extremely strong"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Case Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End Select
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With

I think that your logic might need a bit of work. What about the case where
ComboBox26.Text <> "CLAY"

--
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, originally posted via msnews.microsoft.com
Owen said:
Hi Macropod

Thanks for the response. You have solved my initial problem. I now have
encountered another problem when trying to extend my code. I have pasted
the
code below. The problem occurs at the first line in the debugger, where i
have used the AND and OR statements. I get a message saying "Type
Mismatch".

Any thoughts here?

Thanks again for your time.

Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox11.Text = "calcareous" Or "carbonate" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Slightly cemented" Or "Moderately
cemented"
Or "Well cemented" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Very weak" Or "Weak" Or "Moderately weak"
Or
"Moderately strong" Or "Strong" Or "Very strong" Or "Extremely strong"
Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End If
End If
End If
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

:

Hi Owen,

Try something along the lines of:
Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


I am using an activex control (combobox) in a macro that exists within
my
word document. I have attached my code below.

The problem is that even when the combobox selection is NOT equal to
CLAY,
the macro still executes the code as if the combobox selection was
CLAY.

Prehaps the "if result =" method is not valid here?

Appreciate any help you can offer.

Sub test()
Dim CB26 As Object
Set CB26 = ActiveDocument.ComboBox26
With CB26
If Result = CLAY Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
End If
End With
End Sub
 
D

Doug Robbins - Word MVP

OK, I figured that the ComboBox11 was a type and should have been
ComboBox1.

I would suggest that you give the comboboxes names that have some meaning to
them.

It also reinforces my believe that your logic needs some work.

--
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, originally posted via msnews.microsoft.com
Owen said:
Hi Doug

I am going to read further into the Select Case function.

Initially though, i can't understand how the function would determine if
"calcareous" or "carbonate" are selected since nowhere is ComboBox11
(which
contains those values) referenced in the code you provided.

I'll do some more research on this function, but let me know if i am
missing
something simple here.

Thanks again

Doug Robbins - Word MVP said:
Try

If ActiveDocument.ComboBox26.Text = "CLAY" Then
Select Case ActiveDocument.ComboBox1.Text
Case "calcareous" Or "carbonate"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Case "Slightly cemented" Or "Moderately cemented" Or "Well
cemented"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Case "Very weak" Or "Weak" Or "Moderately weak" Or "Moderately
strong" _
Or "Strong" Or "Very strong" Or "Extremely strong"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Case Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End Select
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With

I think that your logic might need a bit of work. What about the case
where
ComboBox26.Text <> "CLAY"

--
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, originally posted via msnews.microsoft.com
Owen said:
Hi Macropod

Thanks for the response. You have solved my initial problem. I now have
encountered another problem when trying to extend my code. I have
pasted
the
code below. The problem occurs at the first line in the debugger, where
i
have used the AND and OR statements. I get a message saying "Type
Mismatch".

Any thoughts here?

Thanks again for your time.

Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox11.Text = "calcareous" Or "carbonate" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Slightly cemented" Or "Moderately
cemented"
Or "Well cemented" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Very weak" Or "Weak" Or "Moderately
weak"
Or
"Moderately strong" Or "Strong" Or "Very strong" Or "Extremely strong"
Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End If
End If
End If
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

:

Hi Owen,

Try something along the lines of:
Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


I am using an activex control (combobox) in a macro that exists
within
my
word document. I have attached my code below.

The problem is that even when the combobox selection is NOT equal to
CLAY,
the macro still executes the code as if the combobox selection was
CLAY.

Prehaps the "if result =" method is not valid here?

Appreciate any help you can offer.

Sub test()
Dim CB26 As Object
Set CB26 = ActiveDocument.ComboBox26
With CB26
If Result = CLAY Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
End If
End With
End Sub
 
O

Owen

I copied your code however i am now getting a message "Type Mismatch" at the
third line of code

Case "calcareous" Or "carbonate"

I am using Word 2003, could this have any effect?



Doug Robbins - Word MVP said:
OK, I figured that the ComboBox11 was a type and should have been
ComboBox1.

I would suggest that you give the comboboxes names that have some meaning to
them.

It also reinforces my believe that your logic needs some work.

--
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, originally posted via msnews.microsoft.com
Owen said:
Hi Doug

I am going to read further into the Select Case function.

Initially though, i can't understand how the function would determine if
"calcareous" or "carbonate" are selected since nowhere is ComboBox11
(which
contains those values) referenced in the code you provided.

I'll do some more research on this function, but let me know if i am
missing
something simple here.

Thanks again

Doug Robbins - Word MVP said:
Try

If ActiveDocument.ComboBox26.Text = "CLAY" Then
Select Case ActiveDocument.ComboBox1.Text
Case "calcareous" Or "carbonate"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Case "Slightly cemented" Or "Moderately cemented" Or "Well
cemented"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Case "Very weak" Or "Weak" Or "Moderately weak" Or "Moderately
strong" _
Or "Strong" Or "Very strong" Or "Extremely strong"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Case Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End Select
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With

I think that your logic might need a bit of work. What about the case
where
ComboBox26.Text <> "CLAY"

--
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, originally posted via msnews.microsoft.com
Hi Macropod

Thanks for the response. You have solved my initial problem. I now have
encountered another problem when trying to extend my code. I have
pasted
the
code below. The problem occurs at the first line in the debugger, where
i
have used the AND and OR statements. I get a message saying "Type
Mismatch".

Any thoughts here?

Thanks again for your time.

Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox11.Text = "calcareous" Or "carbonate" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Slightly cemented" Or "Moderately
cemented"
Or "Well cemented" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Very weak" Or "Weak" Or "Moderately
weak"
Or
"Moderately strong" Or "Strong" Or "Very strong" Or "Extremely strong"
Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End If
End If
End If
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

:

Hi Owen,

Try something along the lines of:
Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


I am using an activex control (combobox) in a macro that exists
within
my
word document. I have attached my code below.

The problem is that even when the combobox selection is NOT equal to
CLAY,
the macro still executes the code as if the combobox selection was
CLAY.

Prehaps the "if result =" method is not valid here?

Appreciate any help you can offer.

Sub test()
Dim CB26 As Object
Set CB26 = ActiveDocument.ComboBox26
With CB26
If Result = CLAY Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Result1"
Selection.Paste
End If
End With
End Sub
 
D

Doug Robbins - Word MVP

Try:

If ActiveDocument.ComboBox26.Text = "CLAY" Then
Select Case ActiveDocument.ComboBox1.Text
Case "calcareous", "carbonate"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Case "Slightly cemented", "Moderately cemented", "Well cemented"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Case "Very weak", "Weak", "Moderately weak", "Moderately strong", _
"Strong", "Very strong", "Extremely strong"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Case Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End Select
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With


--
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, originally posted via msnews.microsoft.com
Owen said:
I copied your code however i am now getting a message "Type Mismatch" at
the
third line of code

Case "calcareous" Or "carbonate"

I am using Word 2003, could this have any effect?



Doug Robbins - Word MVP said:
OK, I figured that the ComboBox11 was a type and should have been
ComboBox1.

I would suggest that you give the comboboxes names that have some meaning
to
them.

It also reinforces my believe that your logic needs some work.

--
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, originally posted via msnews.microsoft.com
Owen said:
Hi Doug

I am going to read further into the Select Case function.

Initially though, i can't understand how the function would determine
if
"calcareous" or "carbonate" are selected since nowhere is ComboBox11
(which
contains those values) referenced in the code you provided.

I'll do some more research on this function, but let me know if i am
missing
something simple here.

Thanks again

:

Try

If ActiveDocument.ComboBox26.Text = "CLAY" Then
Select Case ActiveDocument.ComboBox1.Text
Case "calcareous" Or "carbonate"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Case "Slightly cemented" Or "Moderately cemented" Or "Well
cemented"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Case "Very weak" Or "Weak" Or "Moderately weak" Or "Moderately
strong" _
Or "Strong" Or "Very strong" Or "Extremely strong"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Case Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End Select
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With

I think that your logic might need a bit of work. What about the case
where
ComboBox26.Text <> "CLAY"

--
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, originally posted via msnews.microsoft.com
Hi Macropod

Thanks for the response. You have solved my initial problem. I now
have
encountered another problem when trying to extend my code. I have
pasted
the
code below. The problem occurs at the first line in the debugger,
where
i
have used the AND and OR statements. I get a message saying "Type
Mismatch".

Any thoughts here?

Thanks again for your time.

Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox11.Text = "calcareous" Or "carbonate" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Slightly cemented" Or "Moderately
cemented"
Or "Well cemented" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Very weak" Or "Weak" Or "Moderately
weak"
Or
"Moderately strong" Or "Strong" Or "Very strong" Or "Extremely
strong"
Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End If
End If
End If
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

:

Hi Owen,

Try something along the lines of:
Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


I am using an activex control (combobox) in a macro that exists
within
my
word document. I have attached my code below.

The problem is that even when the combobox selection is NOT equal
to
CLAY,
the macro still executes the code as if the combobox selection
was
CLAY.

Prehaps the "if result =" method is not valid here?

Appreciate any help you can offer.

Sub test()
Dim CB26 As Object
Set CB26 = ActiveDocument.ComboBox26
With CB26
If Result = CLAY Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark,
Name:="Result1"
Selection.Paste
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark,
Name:="Result1"
Selection.Paste
End If
End With
End Sub
 
O

Owen

Awesome, that did it.

Thanks so much for your help.

Doug Robbins - Word MVP said:
Try:

If ActiveDocument.ComboBox26.Text = "CLAY" Then
Select Case ActiveDocument.ComboBox1.Text
Case "calcareous", "carbonate"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Case "Slightly cemented", "Moderately cemented", "Well cemented"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Case "Very weak", "Weak", "Moderately weak", "Moderately strong", _
"Strong", "Very strong", "Extremely strong"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Case Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End Select
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With


--
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, originally posted via msnews.microsoft.com
Owen said:
I copied your code however i am now getting a message "Type Mismatch" at
the
third line of code

Case "calcareous" Or "carbonate"

I am using Word 2003, could this have any effect?



Doug Robbins - Word MVP said:
OK, I figured that the ComboBox11 was a type and should have been
ComboBox1.

I would suggest that you give the comboboxes names that have some meaning
to
them.

It also reinforces my believe that your logic needs some work.

--
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, originally posted via msnews.microsoft.com
Hi Doug

I am going to read further into the Select Case function.

Initially though, i can't understand how the function would determine
if
"calcareous" or "carbonate" are selected since nowhere is ComboBox11
(which
contains those values) referenced in the code you provided.

I'll do some more research on this function, but let me know if i am
missing
something simple here.

Thanks again

:

Try

If ActiveDocument.ComboBox26.Text = "CLAY" Then
Select Case ActiveDocument.ComboBox1.Text
Case "calcareous" Or "carbonate"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Case "Slightly cemented" Or "Moderately cemented" Or "Well
cemented"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Case "Very weak" Or "Weak" Or "Moderately weak" Or "Moderately
strong" _
Or "Strong" Or "Very strong" Or "Extremely strong"
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Case Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End Select
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With

I think that your logic might need a bit of work. What about the case
where
ComboBox26.Text <> "CLAY"

--
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, originally posted via msnews.microsoft.com
Hi Macropod

Thanks for the response. You have solved my initial problem. I now
have
encountered another problem when trying to extend my code. I have
pasted
the
code below. The problem occurs at the first line in the debugger,
where
i
have used the AND and OR statements. I get a message saying "Type
Mismatch".

Any thoughts here?

Thanks again for your time.

Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox11.Text = "calcareous" Or "carbonate" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample6"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Slightly cemented" Or "Moderately
cemented"
Or "Well cemented" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" And
ActiveDocument.ComboBox1.Text = "Very weak" Or "Weak" Or "Moderately
weak"
Or
"Moderately strong" Or "Strong" Or "Very strong" Or "Extremely
strong"
Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample16"
Else
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
End If
End If
End If
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

:

Hi Owen,

Try something along the lines of:
Sub test()
If ActiveDocument.ComboBox26.Text = "CLAY" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
End If
With Selection
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Copy
.GoTo What:=wdGoToBookmark, Name:="Result1"
.Paste
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


I am using an activex control (combobox) in a macro that exists
within
my
word document. I have attached my code below.

The problem is that even when the combobox selection is NOT equal
to
CLAY,
the macro still executes the code as if the combobox selection
was
CLAY.

Prehaps the "if result =" method is not valid here?

Appreciate any help you can offer.

Sub test()
Dim CB26 As Object
Set CB26 = ActiveDocument.ComboBox26
With CB26
If Result = CLAY Then
Selection.GoTo What:=wdGoToBookmark, Name:="Sample1"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark,
Name:="Result1"
Selection.Paste
Else
Selection.GoTo What:=wdGoToBookmark, Name:="Sample11"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Copy
Selection.GoTo What:=wdGoToBookmark,
Name:="Result1"
Selection.Paste
End If
End With
End Sub
 

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