View Single Post
  #8   Report Post  
Posted to microsoft.public.word.docmanagement
owen owen is offline
external usenet poster
 
Posts: 61
Default Activex Control in Word Document

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" wrote:

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" wrote in message
...
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" wrote:

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" wrote in message
...
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" wrote:

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" wrote in message
...
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