populating a listbox, initialize problem?

N

natanz

I am developing a template that uses an excel spreadsheet to populate a
listbox on a userform. I am basing my work on the sample code i found
at:

http://word.mvps.org/FAQs/InterDev/FillListBoxFromXLDAO.htm

I created a userform with a single listbox in it called listbox1.

I also made a sub called autonew

Public Sub AutoNew()
UserForm1.Show
End Sub

But when i create a new document based on this template, the userform
shows up, but it doesn't seem like it initialized. there is no list in
the listbox. I am new at this, so i must be missing something,
probably very simple. any help would be appreciated.

thanks
 
N

natanz

Ok, i solved the problem without actually figuring it out. initially,
i typed in the code from the web site listed above which didn't work.
when i cut and paste the line
Set rs = db.OpenRecordset("SELECT * FROM `myDatabase`") it worked. It
seems i misinterpreted the two characters around the word myDatabase as
single quotes, but they must be something different. I am not sure
what they are, but at least now i have them in my code.

Now i am on to a new problem.

I have written the following piece of code:

Private Sub CommandButton1_Click()
Dim projnum As String

projnum = UserForm1.ListBox1.Text
ActiveDocument.FormFields("text19").Result = projnum
UserForm1.Hide
MsgBox projnum

End Sub

the idea is that it takes the selection from the UserForm1 Listbox, and
puts it in the document at the location called "text19" I put in the
msgbox, just to check my work. but it is not working. somehow the
variable projnum doesn't seem to be set. Again this was code that i
adapted from tutorials that i found on the web. What am i missing?
 

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