Adding Item to ComboBox

N

Nik

Hi Friends,

I am working on an application in VB6.0 which creates Word document on the fly.
I have added a ComboBox control to the page, but I am not able to add the individual ListItems to this Combo Box.


I am not getting any run time errors, but when I open the created document it doesn't show me any Item in the ComboBox.

Following is the code I am trying.


Set MyInLineShape = MyTable.Cell(1, 1).Range.InlineShapes.AddOLEControl("Forms.ComboBox.1")
MyInLineShape.OLEFormat.object.Style = 2
MyInLineShape.OLEFormat.object.AddItem "Item 1"
MyInLineShape.OLEFormat.object.AddItem "Item 2"
MyInLineShape.OLEFormat.object.AddItem "Item 3"
MyInLineShape.OLEFormat.object.AddItem "Item 4"


Kindly Help,

Thanks and Regards,
Nik
 
P

Peter Hewett

Hi Nik

I haven't got my VB6 system booted at the moment so I've only been able to
try a version of your code from within Word 2000. I created a dummy
document and added a table. I then ran the following code:

Public Sub Crappo()
Dim ilsCombo As Word.InlineShape

Set ilsCombo = ActiveDocument.Tables(1).Cell(1, 1).Range._
InlineShapes.AddOLEControl("Forms.ComboBox.1")
With ilsCombo_OLEFormat.Object
.Style = 2 ' fmStyleDropDownList
.AddItem "one"
.AddItem "two"
.AddItem "three"
End With
End Sub

Everything worked as expected. It added an ActiveX ComboBox control to cell
(1,1). When I clicked on the drop down it displayed the three items.

If the VB app is creating the control I can't see why it's not populating
it. Have you tried your code from within the VBA environment?

Cheers - Peter
 
N

Nik

Hi Peter

Thanks a ton for your response

I tried the code given by you in my Word 2000 and it worked like charm

I don't know why the same thing is not working in VB6.

I am pasting my simplified VB6.0 code

Private Sub CreateDoc(
Dim doc As Word.Documen
Set doc = Application.Documents.Add(, , Word.WdNewDocumentType.wdNewBlankDocument, False
Dim MyInLineShape As InlineShap
Set MyInLineShape = doc.Range.InlineShapes.AddOLEControl("Forms.ComboBox.1"

MyInLineShape.OLEFormat.Activat
MyInLineShape.OLEFormat.object.AddItem "Nik
MyInLineShape.OLEFormat.object.AddItem "Peter


doc.SaveAs ("C:\Nik\01\D.doc"
doc.Clos

En
End Su

Really appreciate your help
Thanks again
Nik
 
P

Perry

Private Sub CreateDoc()
Dim doc As Word.Document
Set doc = Application.Documents.Add(, ,
Word.WdNewDocumentType.wdNewBlankDocument, False)
Dim MyInLineShape As InlineShape
Set MyInLineShape =
doc.Range.InlineShapes.AddOLEControl("Forms.ComboBox.1")

Are you sure this is the code listed in VB6?

If so, this won't work because of
Set doc = Application.Documents.Add
Your VB6 project, has to have a valid Word automation (application)
object. The above statement doesn't have that, unless y've declared
"Application" as yr Word application object.

Do something like:
Dim wdApp As New word.Application

and replace above statement by
Set doc = wdApp.Documents.Add ... etc.

I haven't analysed the rest of yr code, but yr code won't work
definitely because of the above ...

Kindly repost of you have any other problem ...

Krgrds,
Perry

Nik said:
Hi Peter,

Thanks a ton for your response.

I tried the code given by you in my Word 2000 and it worked like charm.

I don't know why the same thing is not working in VB6.0

I am pasting my simplified VB6.0 code:

Private Sub CreateDoc()
Dim doc As Word.Document
Set doc = Application.Documents.Add(, ,
Word.WdNewDocumentType.wdNewBlankDocument, False)
 

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