Populate Word UserForm Combo Box from Access

N

N. Cotton

Does anyone know how to reference/populate a combo box which is on a userform
within a Word document.

I am trying to overcome the 25 item limit on a drop down combo box on a Word
form.

The way to do this seems to be to create a UserForm and add the combo box
onto that. - this allows more than 25 items, but i cannot see how to
populate it from within Access.

The normal combo boxes on the document I populate like this:
doc.FormFields("EmployeeName").Dropdown.ListEntries.Add Name:=rs!employeename

I can populate the combo box on the userform from a Macro in the document
itself which then gets the information from the database, but I want to do it
the other way round - populate it form within access.

Any help greatly appreciated.
 
N

N. Cotton

You know this really has annoyed me - now anyone reading this will just see
your incorrect reply and not bother trying to help!
 
J

James A. Fortune

N. Cotton said:
Does anyone know how to reference/populate a combo box which is on a userform
within a Word document.

I am trying to overcome the 25 item limit on a drop down combo box on a Word
form.

The way to do this seems to be to create a UserForm and add the combo box
onto that. - this allows more than 25 items, but i cannot see how to
populate it from within Access.

The normal combo boxes on the document I populate like this:
doc.FormFields("EmployeeName").Dropdown.ListEntries.Add Name:=rs!employeename

I can populate the combo box on the userform from a Macro in the document
itself which then gets the information from the database, but I want to do it
the other way round - populate it form within access.

Any help greatly appreciated.

One way is to use a Reference within Access to the Excel Object Library.
The code in Access will be quite similar to your Excel Macro code, but
there might be some differences. For example,

ChDir "C:\"
Workbooks.Open FileName:="C:\Book1.xls"

might become:

strFileName = "C:\Book1.xls"
objXL.Workbooks.Open(strFileName)

Access doesn't seem to do well with :=. Also, it's important to
reference everything from the top of the object model (or from an object
so referenced, perhaps using With ... End With when convenient) on down.
It's similar to using full paths rather than relative paths.

Post back if you have more questions.

James A. Fortune
[email protected]
 
N

N. Cotton

Thanks for the raply James.

I can successfully reference the form fields etc on the Word document from
within Access. What I am struggling with is referenceing fields on an
underlying userform contained in the Word document.
 
J

James A. Fortune

N. Cotton said:
Thanks for the raply James.

I can successfully reference the form fields etc on the Word document from
within Access. What I am struggling with is referenceing fields on an
underlying userform contained in the Word document.

Oops. Word -- not Excel. Even though I've never used a userform in
Word, I've accessed other things in Word like tables and found that I
was always able to take the macro code and make it run in Access. If
you can post some of the macro code you get when you record a macro that
references a userform value (perhaps by hitting Record, changing a value
on the userform and then stopping the recording), I might be able to
help you massage the macro code into Access VBA.

James A. Fortune
[email protected]
 
Top