From Word, need to populate list or combobox from Excel SS 
Author Message
 From Word, need to populate list or combobox from Excel SS

In Word XP, I need a simple way to populate a list box with an Excel SS. I
would like to link to all of the other data behind the SS after a record is
selected.

Any Ideas?

Regards,

Mark



Thu, 24 Nov 2005 02:49:59 GMT  
 From Word, need to populate list or combobox from Excel SS
Hi Mark,

See the article Load a ListBox from a Named Range in Excel using DAO at:

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

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:
> In Word XP, I need a simple way to populate a list box with an Excel SS. I
> would like to link to all of the other data behind the SS after a record
is
> selected.

> Any Ideas?

> Regards,

> Mark



Thu, 24 Nov 2005 06:31:39 GMT  
 From Word, need to populate list or combobox from Excel SS
Thanks Doug

Yes, I've been working from this very code example for a couple of hours
now. For some reason, I can't get the listbox to populate. I've tried DAO
3.51 and 3.6.

I've implemented the example almost verbatim (except for the path and
filename)

Any suggestions?

Regards,

Mark



Quote:
> Hi Mark,

> See the article "Load a ListBox from a Named Range in Excel using DAO" at:

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

> Please respond to the newsgroups for the benefit of others who may be
> interested.

> Hope this helps
> Doug Robbins - Word MVP


> > In Word XP, I need a simple way to populate a list box with an Excel SS.
I
> > would like to link to all of the other data behind the SS after a record
> is
> > selected.

> > Any Ideas?

> > Regards,

> > Mark



Thu, 24 Nov 2005 10:46:11 GMT  
 From Word, need to populate list or combobox from Excel SS
Hi Mark,

I just tested the code from that article and it works fine for me, loading
ListBox1 with the data from a range that I named AccountCodes in an Excel
Worksheet named Accounts in the H:\Access97 folder on my PC.

Here is the code that I used:

Private Sub UserForm_Initialize()

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim NoOfRecords As Long

    ' Open the database
    Set db = OpenDatabase("h:\Access97\Accounts.xls", False, False, "Excel
8.0")

    ' Retrieve the recordset
    Set rs = db.OpenRecordset("SELECT * FROM AccountCodes")

    ' Determine the number of retrieved records
    With rs
         .MoveLast
         NoOfRecords = .RecordCount
         .MoveFirst
    End With

    ' Set the number of Columns = number of Fields in recordset
    ListBox1.ColumnCount = rs.Fields.Count

    ' Load the ListBox with the retrieved records
    ListBox1.Column = rs.GetRows(NoOfRecords)

    ' Cleanup
    rs.Close
    db.Close

    Set rs = Nothing
    Set db = Nothing

End Sub

I note that the code on the web page has myDatabase surrounded by a pair of
` i.e. `myDataBase`  I thought that you may have included them and that is
what's causing your problem, but I have just tried my code again with the
following command

    Set rs = db.OpenRecordset("SELECT * FROM `AccountCodes`")

instead of the corresponding line in the code above, and it works fine.  In
other words, the `` appear to be ignored by VBA which I admit does surprise
me.  Did you however use to apostropes instead of that symbol whatever it
is.  If you use apostrophes, you will get a Run-time error '3450':  Syntax
eror in query.  Incomplete query clause.

If this information doesn't help you overcome your problem,  paste the code
from your Iitialize() event into a message that you post back to the ng so
that we can see what you have.

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:
> Thanks Doug

> Yes, I've been working from this very code example for a couple of hours
> now. For some reason, I can't get the listbox to populate. I've tried DAO
> 3.51 and 3.6.

> I've implemented the example almost verbatim (except for the path and
> filename)

> Any suggestions?

> Regards,

> Mark



> > Hi Mark,

> > See the article "Load a ListBox from a Named Range in Excel using DAO"
at:

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

> > Please respond to the newsgroups for the benefit of others who may be
> > interested.

> > Hope this helps
> > Doug Robbins - Word MVP


> > > In Word XP, I need a simple way to populate a list box with an Excel
SS.
> I
> > > would like to link to all of the other data behind the SS after a
record
> > is
> > > selected.

> > > Any Ideas?

> > > Regards,

> > > Mark



Thu, 24 Nov 2005 16:36:34 GMT  
 From Word, need to populate list or combobox from Excel SS
My bad, after all that, it was the initialize statement. Thanks Doug, it
works like a champ.

MN



Quote:
> Hi Mark,

> I just tested the code from that article and it works fine for me, loading
> ListBox1 with the data from a range that I named AccountCodes in an Excel
> Worksheet named Accounts in the H:\Access97 folder on my PC.

> Here is the code that I used:

> Private Sub UserForm_Initialize()

>     Dim db As DAO.Database
>     Dim rs As DAO.Recordset
>     Dim NoOfRecords As Long

>     ' Open the database
>     Set db = OpenDatabase("h:\Access97\Accounts.xls", False, False, "Excel
> 8.0")

>     ' Retrieve the recordset
>     Set rs = db.OpenRecordset("SELECT * FROM AccountCodes")

>     ' Determine the number of retrieved records
>     With rs
>          .MoveLast
>          NoOfRecords = .RecordCount
>          .MoveFirst
>     End With

>     ' Set the number of Columns = number of Fields in recordset
>     ListBox1.ColumnCount = rs.Fields.Count

>     ' Load the ListBox with the retrieved records
>     ListBox1.Column = rs.GetRows(NoOfRecords)

>     ' Cleanup
>     rs.Close
>     db.Close

>     Set rs = Nothing
>     Set db = Nothing

> End Sub

> I note that the code on the web page has myDatabase surrounded by a pair
of
> ` i.e. `myDataBase`  I thought that you may have included them and that is
> what's causing your problem, but I have just tried my code again with the
> following command

>     Set rs = db.OpenRecordset("SELECT * FROM `AccountCodes`")

> instead of the corresponding line in the code above, and it works fine.
In
> other words, the `` appear to be ignored by vba which I admit does
surprise
> me.  Did you however use to apostropes instead of that symbol whatever it
> is.  If you use apostrophes, you will get a Run-time error '3450':  Syntax
> eror in query.  Incomplete query clause.

> If this information doesn't help you overcome your problem,  paste the
code
> from your Iitialize() event into a message that you post back to the ng so
> that we can see what you have.

> Please respond to the newsgroups for the benefit of others who may be
> interested.

> Hope this helps
> Doug Robbins - Word MVP


> > Thanks Doug

> > Yes, I've been working from this very code example for a couple of hours
> > now. For some reason, I can't get the listbox to populate. I've tried
DAO
> > 3.51 and 3.6.

> > I've implemented the example almost verbatim (except for the path and
> > filename)

> > Any suggestions?

> > Regards,

> > Mark



> > > Hi Mark,

> > > See the article "Load a ListBox from a Named Range in Excel using DAO"
> at:

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

> > > Please respond to the newsgroups for the benefit of others who may be
> > > interested.

> > > Hope this helps
> > > Doug Robbins - Word MVP


> > > > In Word XP, I need a simple way to populate a list box with an Excel
> SS.
> > I
> > > > would like to link to all of the other data behind the SS after a
> record
> > > is
> > > > selected.

> > > > Any Ideas?

> > > > Regards,

> > > > Mark



Sat, 26 Nov 2005 07:32:57 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Use list from excel or access to populate combo/list box

2. Printing an Excel SS from Word

3. How do I Populate List/ComboBox?

4. Populating a Word ComboBox Containing Outlook Contacts?

5. Combobox Populated by Word Table

6. Need a function to populate ComboBox

7. How to use Excel to populate List Box and Template

8. Populating List Box from File Outside of Word

9. VBA Excel - Populate Excel UserForm ComboBox - & Keep it Populated

10. Time() returning hh:mm:ss tt and not HH:mm:ss

11. ′How to list tables in an Acce ss database with visual basic 6

12. Populate List Box with Large List

 

 
Powered by phpBB® Forum Software